diff --git a/htdocs/core/ajax/mailtemplate.php b/htdocs/core/ajax/mailtemplate.php index 58257ad0d2f..11d4b4ca1cb 100644 --- a/htdocs/core/ajax/mailtemplate.php +++ b/htdocs/core/ajax/mailtemplate.php @@ -21,6 +21,7 @@ * \brief File to return Ajax response on location_incoterms request */ + // Just for display errors in editor ini_set('display_errors', 1); diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 17fc98dc074..72fd29168ad 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1560,7 +1560,6 @@ class FormMail extends Form // Remplacer la variable de substitution dans le contenu HTML contentHtml = contentHtml.replace(/__SUBJECT__/g, subject); - // Envoyer le contenu HTML à process_template.php pour traitement PHP $.ajax({ type: "POST", diff --git a/htdocs/core/lib/emaillayout.lib.php b/htdocs/core/lib/emaillayout.lib.php index d5afc4b1fee..55d4d620a42 100644 --- a/htdocs/core/lib/emaillayout.lib.php +++ b/htdocs/core/lib/emaillayout.lib.php @@ -41,6 +41,8 @@ function getHtmlOfLayout($name) '__USERSIGNATURE__' => !empty($user->signature) ? dol_htmlentities($user->signature) : '', '__GRAY_RECTANGLE__' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAABGklEQVR4nO3SwQ3AIBDAsNLJb3SWIEJC9gR5ZM3MB6f9twN4k7FIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIuEsUgYi4SxSBiLhLFIGIvEBtxYAkgpLmAeAAAAAElFTkSuQmCC', '__LAST_NEWS__' => $langs->trans('LastNews'), + '__LIST_PRODUCTS___' => $langs->trans('ListProducts'), + ); $substitutionarray = array_merge($commonSubstitutionArray, $specificSubstitutionArray); diff --git a/htdocs/install/doctemplates/maillayout/commerce.html b/htdocs/install/doctemplates/maillayout/commerce.html index a54286c2243..c23571544b0 100644 --- a/htdocs/install/doctemplates/maillayout/commerce.html +++ b/htdocs/install/doctemplates/maillayout/commerce.html @@ -1,45 +1,44 @@ -

Lorem, ipsum dolor sit amet consectetur adipisicing elit sit amet consectetur

+

__LIST_PRODUCTS___

Lorem, ipsum dolor sit amet consectetur adipisicing elitsit amet consectetur adipisicing

-
-
-
- Gray rectangle -
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit... -
-
+ + +require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; -
-
- Gray rectangle -
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit... -
-
+$user = new User($db); +$product = new Product($db); +$products = $product->getProductsToPreviewInEmail(4); + + + if (empty($products)){ + print '

No Products

'; + }else { + foreach($products as $product){ + if ($i % 2 == 0) { + print '
'; + } + + print '
+ +
+ Gray rectangle +
+
+

'.$product["ref"].'

+

'.$product["description"].'

+
+
'; + + if ($i % 2 == 1 || $i == $num - 1) { + print '
'; + } + + $i++; + } + } +
- -
- -
-
- Gray rectangle -
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit... -
-
- -
-
- Gray rectangle -
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit... -
-
-
-
\ No newline at end of file + diff --git a/htdocs/install/doctemplates/maillayout/news.html b/htdocs/install/doctemplates/maillayout/news.html index 37399d48956..4768a4419db 100644 --- a/htdocs/install/doctemplates/maillayout/news.html +++ b/htdocs/install/doctemplates/maillayout/news.html @@ -4,3 +4,4 @@ __NEWS_LIST__ + diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 1e82b31a5d1..78b80b21fdf 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -197,4 +197,5 @@ YouCanChooseAModelForYouMailContent= You can choose one of template models or ge TitleOfMailHolder=Title of the e-mail goes here ContentOfMailHolder=Content of email goes here... LastNews=Last News +ListProducts= List of products PasswordReset=Password reset diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e71d97c7079..f58b9032b68 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -6944,6 +6944,51 @@ class Product extends CommonObject $return .= ''; return $return; } + + /** + * Retrieve and display products. + * + * @param int $limit The maximum number of results to return. + * @return array>|int return array if OK, -1 if KO + */ + public function getProductsToPreviewInEmail($limit) + { + + if (!is_numeric($limit)) { + return -1; + } + + $sql = "SELECT p.rowid, p.ref, p.label, p.description, p.entity, ef.filename + FROM ".MAIN_DB_PREFIX."product AS p + JOIN ".MAIN_DB_PREFIX."ecm_files AS ef ON p.rowid = ef.src_object_id + WHERE ef.entity IN (".getEntity('product').") + AND (ef.filename LIKE '%.png' OR ef.filename LIKE '%.jpeg' OR ef.filename LIKE '%.svg') + GROUP BY p.rowid, p.ref, p.label, p.description, p.entity, ef.filename + ORDER BY p.datec ASC + LIMIT " . ((int) $limit); + + $resql = $this->db->query($sql); + $products = array(); + + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $products[] = array( + 'rowid' => $obj->rowid, + 'ref' => $obj->ref, + 'label' => $obj->label, + 'description' => $obj->description, + 'entity' => $obj->entity, + 'filename' => $obj->filename + ); + } + } else { + dol_print_error($this->db); + } + if (empty($products)) { + return -1; + } + return $products; + } } /**