27ini_set(
'display_errors', 1);
29if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
41require_once
'../../main.inc.php';
51require_once
'../lib/files.lib.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
73if (GETPOSTISSET(
'template')) {
76 $content = file_get_contents($templatefile);
78 if ($content ===
false) {
79 print
'Failed to load template '.dol_escape_htmltag(
GETPOST(
'template'));
85 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
88 $mycompanyaddress =
$mysoc->getFullAddress(0,
',', 1,
'');
90 $specificSubstitutionArray = array(
91 '__TITLEOFMAILHOLDER__' => $langs->trans(
'TitleOfMailHolder'),
92 '__CONTENTOFMAILHOLDER__' => $langs->trans(
"ContentOfMailHolder"),
93 '__GRAY_RECTANGLE__' =>
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAABGklEQVR4nO3SwQ3AIBDAsNLJb3SWIEJC9gR5ZM3MB6f9twN4k7FIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIvEBtxYAkgpLmAeAAAAAElFTkSuQmCC',
94 '__LAST_NEWS__' => $langs->trans(
'LastNews'),
95 '__LIST_PRODUCTS___' => $langs->trans(
'ListProducts'),
96 '__SUBJECT__' =>
GETPOST(
'subject'),
98 '__MYCOMPANY_NAME__' =>
$mysoc->name,
99 '__MYCOMPANY_ADDRESS__' => $mycompanyaddress,
100 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
101 '__MYCOMPANY_PHONE__' =>
$mysoc->phone,
102 '__MYCOMPANY_PHONE_MOBILE__' =>
$mysoc->phone_mobile,
103 '__MYCOMPANY_FAX__' =>
$mysoc->fax,
105 '__MYCOMPANY_ADDRESS_WITH_PICTO__' => $mycompanyaddress ?
'<img src="data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBzdHJva2U9IiMwMDAiIHN0cm9rZS13aWR0aD0iNCIgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGQ9Ik0xMiAyMmM1LjUyIDAgMTAtNC40OCAxMC0xMFMxNy41MiAyIDEyIDIgMiA2LjQ4IDIgMTJzNC40OCAxMCAxMCAxMHoiLz4KICA8Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIzIi8+Cjwvc3ZnPg==" style="height: 20px; width: 20px; display: inline-block; vertical-align: middle;"> ' . $mycompanyaddress :
'',
106 '__MYCOMPANY_EMAIL_WITH_PICTO__' =>
$mysoc->
email ?
'<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCIgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0Ij4KICA8cmVjdCB4PSI0IiB5PSIxMiIgd2lkdGg9IjU2IiBoZWlnaHQ9IjQwIiByeD0iNCIgcnk9IjQiIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzAwMCIgc3Ryb2tlLXdpZHRoPSI0Ii8+CiAgPHBvbHlsaW5lIHBvaW50cz0iNiwxNCAzMiwzNiA1OCwxNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMDAwIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+" style="height: 20px; width: 20px; display: inline-block; vertical-align: middle;"> ' .
$mysoc->
email :
'',
107 '__MYCOMPANY_PHONE_PRO_WITH_PICTO__' =>
$mysoc->phone ?
'<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIHY3LjAuMCBieSBAYm9udGF3ZXNvbWUgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbSBMaWNlbnNlIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20vbGljZW5zZS9mcmVlIENvcHlyaWdodCAyMDI1IEZvbnRjb25zLCBJbmMuLS0+PHBhdGggZD0iTTE2MC4yIDI1QzE1Mi4zIDYuMSAxMzEuNy0zLjkgMTEyLjEgMS40bC01LjUgMS41Yy02NC42IDE3LjYtMTE5LjggODAuMi0xMDMuNyAxNTYuNCAzNy4xIDE3NSA3NC44IDMxMi43IDM0OS44IDM0OS44IDc2LjMgMTYuMiAxMzguOC0zOS4xIDE1Ni40LTEwMy43bDEuNS01LjVjNS40LTE5LjctNC43LTQwLjMtMjMuNS00OC4xbC05Ny4zLTQwLjVjLTE2LjUtNi45LTM1LjYtMi4xLTQ3IDExLjhsLTM4LjYgNDcuMkMyMzMuOSAzMzUuNCAxNzcuMyAyNzcgMTQ0LjggMjA1LjNMMTg5IDE2OS4zYzEzLjktMTEuMyAxOC42LTMwLjQgMTEuOC00N0wxNjAuMiAyNXoiLz48L3N2Zz4=" style="height: 20px; width: 20px; display: inline-block; vertical-align: middle;"> ' .
$mysoc->phone :
'',
110 $listsocialnetworks =
'';
117 $specificSubstitutionArray[
'__MYCOMPANY_SOCIAL_NETWORKS__'] = $listsocialnetworks;
120 $specificSubstitutionArray[
'__LOGO_URL__'] = $urlwithroot.
'/viewimage.php?modulepart=mycompany&file='.urlencode(
'logos/'.
$mysoc->logo);
122 $specificSubstitutionArray[
'__LOGO_URL__'] =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAABGklEQVR4nO3SwQ3AIBDAsNLJb3SWIEJC9gR5ZM3MB6f9twN4k7FIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIvEBtxYAkgpLmAeAAAAAElFTkSuQmCC';
125 $specificSubstitutionArray[
'__USERSIGNATURE__'] = empty($user->signature) ?
'' : $user->signature;
127 if (
GETPOST(
'fromtype') ==
'user') {
128 $specificSubstitutionArray[
'__SENDEREMAIL_SIGNATURE__'] = empty($user->signature) ?
'' : $user->signature;
129 } elseif (
GETPOST(
'fromtype') ==
'company') {
130 $specificSubstitutionArray[
'__SENDEREMAIL_SIGNATURE__'] =
$mysoc->name.
' '.
$mysoc->email;
131 } elseif (
GETPOST(
'fromtype') ==
'main_from') {
132 $specificSubstitutionArray[
'__SENDEREMAIL_SIGNATURE__'] =
$mysoc->name.
' '.
getDolGlobalString(
'MAIN_MAIL_EMAIL_FROM');
135 $specificSubstitutionArray[
'__SENDEREMAIL_SIGNATURE__'] =
'TODO Read database to get the signature of the profile';
141 foreach ($specificSubstitutionArray as $key => $val) {
142 $content = str_replace($key, $val, $content);
146 $langs->load(
"other");
147 $content = preg_replace_callback(
153 function ($matches) {
155 return $langs->trans($matches[1]);
160 $template =
GETPOST(
'template',
'alpha');
162 $selectedIdsStr =
GETPOST(
'selectedPosts',
'alpha');
164 $selectedIds = json_decode($selectedIdsStr);
165 if (is_numeric($selectedIds)) {
166 $selectedIds = array($selectedIds);
180 if (!empty($selectedIds) && !empty($template) && is_array($selectedIds) ) {
183 foreach ($selectedIds as $Id) {
184 if ($template ==
"news") {
187 $newsList .=
'<div style="display: flex; align-items: flex-start; justify-content: flex-start; width: 100%; max-width: 800px; margin-top: 20px;margin-bottom: 50px; padding: 20px;">
188 <div style="flex-grow: 1; margin-right: 30px; max-width: 600px; margin-left: 100px;">
189 <h2 style="margin: 0; font-size: 1.5em;">' . (empty($post[
'title']) ?
'' :
dol_htmlentitiesbr($post[
'title'])) .
'</h2>
190 <p style="margin: 10px 0; color: #555;">' . (empty($post[
'description']) ?
'' :
dol_htmlentitiesbr($post[
'description'])) .
'</p>
191 <span style="display: block; margin-bottom: 5px; color: #888;">Created By: <strong>' .
dol_htmlentitiesbr(empty($post[
'user_fullname']) ?
'' : $post[
'user_fullname']) .
'</strong></span>
193 <span style="display: block; color: #888;">' .
dol_print_date((empty($post[
'date_creation']) ?
dol_now() : $post[
'date_creation']),
'daytext',
'tzserver', $langs) .
'</span>
195 <div style="flex-shrink: 0; margin-left: 100px; float: right;">
196 ' . (!empty($post[
'image']) ?
'<img alt="Image" width="130px" height="130px" style="border-radius: 10px;" src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=medias&file=' .
dol_htmlentitiesbr($post[
'image']) .
'">' :
'<img alt="Gray rectangle" width="130px" height="130px" style="border-radius: 10px;" src="__GRAY_RECTANGLE__">') .
'
199 } elseif ($template ==
"product") {
202 $productList .=
'<div style="width:100%; padding: 20px;">
204 ' . (!empty($product[
'image']) ?
dol_htmlentitiesbr($product[
'image']) :
'<img alt="Gray rectangle" width="130px" height="130px" style="border-radius: 10px;" src="__GRAY_RECTANGLE__">') .
'
208 <p style="margin: 10px 0; color: #555;">'. (empty($product[
'description']) ?
'' :
dol_htmlentitiesbr($product[
'description'])) .
'</p>
215 $content = str_replace(
'__NEWS_LIST__', $newsList, $content);
216 $content = str_replace(
'__PRODUCT_SELECTED__', $productList, $content);
218 $content = str_replace(
'__NEWS_LIST__', $langs->trans(
"SelectSomeArticlesOrEnterYourOwnContent"), $content);
219 $content = str_replace(
'__PRODUCT_SELECTED__', $langs->trans(
"SelectOneArticleOrEnterYourOwnContent"), $content);
222 foreach ($specificSubstitutionArray as $key => $val) {
223 $content = str_replace($key, $val, $content);
228 print
'No template ID provided or expired token';
global $dolibarr_main_url_root
getNewsDetailsById($postId)
Retrieves the details of a news post by its ID.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
getProductForEmailTemplate($id)
Retrieve and return product for mail template.