dolibarr 22.0.5
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
29//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
30//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
31if (!defined('NOTOKENRENEWAL')) {
32 define('NOTOKENRENEWAL', '1');
33}
34if (!defined('NOREQUIREMENU')) {
35 define('NOREQUIREMENU', '1');
36}
37if (!defined('NOREQUIREHTML')) {
38 define('NOREQUIREHTML', '1');
39}
40if (!defined('NOREQUIREAJAX')) {
41 define('NOREQUIREAJAX', '1');
42}
43
44// Load Dolibarr environment
45require '../main.inc.php'; // Load $user and permissions
46require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
48
56$facid = GETPOSTINT('facid');
57$action = GETPOST('action', 'aZ09');
58$email = GETPOST('email', 'alpha');
59
60if (!$user->hasRight('takepos', 'run')) {
62}
63
64$langs->loadLangs(array("main", "bills", "cashdesk"));
65
66$invoice = new Facture($db);
67$result = $invoice->fetch($facid);
68// Only an invoice of the POS, in an entity of the user, can be sent from the POS
69if ($result <= 0 || $invoice->module_source != 'takepos' || !in_array($invoice->entity, explode(',', getEntity('invoice')))) {
71}
72
73$customer = new Societe($db);
74$customer->fetch($invoice->socid);
75
76
77/*
78 * Actions
79 */
80
81if ($action == "send" && $user->hasRight('takepos', 'run')) {
82 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
83 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
84 $formmail = new FormMail($db);
85 $outputlangs = new Translate('', $conf);
86 $model_id = getDolGlobalInt('TAKEPOS_EMAIL_TEMPLATE_INVOICE');
87 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'facture_send', $user, $outputlangs, $model_id);
88 $subject = $arraydefaultmessage->topic;
89
90 ob_start(); // turn on output receipt
91 include DOL_DOCUMENT_ROOT.'/takepos/receipt.php';
92 $receipt = ob_get_contents(); // get the contents of the output buffer
93 ob_end_clean();
94
95 $msg = "<html>".$arraydefaultmessage->content."<br>".$receipt."</html>";
96 $sendto = $email;
97 $from = $mysoc->email;
98 $mail = new CMailFile($subject, $sendto, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', '', '', '', '', DOL_DATA_ROOT.'/documents/takepos/temp');
99 if ($mail->error || !empty($mail->errors)) {
100 setEventMessages($mail->error, $mail->errors, 'errors');
101 } else {
102 $result = $mail->sendfile();
103 }
104 exit;
105}
106
107
108/*
109 * View
110 */
111
112$arrayofcss = array('/takepos/css/pos.css.php');
113$arrayofjs = array();
114$head = '';
115
116top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
117
118?>
119<body class="center">
120
121<script>
122function SendMail() {
123 $.ajax({
124 type: "GET",
125 data: { token: '<?php echo currentToken(); ?>' },
126 url: "<?php print DOL_URL_ROOT.'/takepos/send.php?action=send&token='.newToken().'&facid='.$facid.'&email='; ?>" + $("#email"). val(),
127 });
128 parent.$.colorbox.close();
129}
130
131</script>
132
133<div class="center">
134<center>
135<center>
136<input type="email" id="email" name="email" style="width:60%;font-size: 200%;" value="<?php echo $customer->email; ?>"></center>
137</center>
138</div>
139<br>
140<div class="center">
141
142<button type="button" class="calcbutton" onclick="SendMail()"><?php print $langs->trans("SendTicket"); ?></button>
143
144</div>
145
146</body>
147</html>
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage invoices.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.