diff --git a/htdocs/core/ajax/getnews.php b/htdocs/core/ajax/getnews.php
new file mode 100644
index 00000000000..9e8b61c47b2
--- /dev/null
+++ b/htdocs/core/ajax/getnews.php
@@ -0,0 +1,48 @@
+fetch($id);
+
+ $selectedPosts[] = array(
+ 'id' => $blog->id,
+ 'title' => $blog->title,
+ 'description' => $blog->description,
+ 'date_creation' => $blog->date_creation,
+ 'image' => $blog->image,
+ );
+ }
+
+ print json_encode($selectedPosts);
+} else {
+ print json_encode(array('error' => 'Invalid request'));
+}
diff --git a/htdocs/core/ajax/mailtemplate.php b/htdocs/core/ajax/mailtemplate.php
index 11d4b4ca1cb..b4d6257fb52 100644
--- a/htdocs/core/ajax/mailtemplate.php
+++ b/htdocs/core/ajax/mailtemplate.php
@@ -44,12 +44,7 @@ require_once '../../main.inc.php';
require_once '../lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
-
-// There is no permission test on this component for the moment. Test will be added when knowing which data it read.
-
-// TODO $selectedPosts is not initialised, i set it to '' but this is surely a bug and not the expected behaviour.
-// Should be set to list of last news...
-$selectedPosts = '';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
/*
@@ -60,12 +55,16 @@ top_httphead();
// TODO Replace with ID of template
if (GETPOSTISSET('content')) {
- $content = GETPOST('content');
+ $content = filter_input(INPUT_POST, 'content', FILTER_UNSAFE_RAW);
- if (!empty($selectedPosts)) {
+ $selectedPostsStr = GETPOST('selectedPosts', 'alpha');
+ $selectedPosts = explode(',', $selectedPostsStr);
+
+ if (is_array($selectedPosts) && !empty($selectedPosts)) {
$newsList = '';
- foreach ($selectedPosts as $post) {
+ foreach ($selectedPosts as $postId) {
+ $post = getNewsDetailsById($postId);
$newsList .= '
' . htmlentities($post['title']) . '
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index d33f5f73f8f..d51d1177e68 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -499,7 +499,7 @@ class FormMail extends Form
$modelmail_array = array();
if ($this->param['models'] != 'none') {
- $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); // Fill $this->lines_model
+ $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
if ($result < 0) {
setEventMessages($this->error, $this->errors, 'errors');
}
@@ -1514,16 +1514,21 @@ class FormMail extends Form
* Return HTML code for selection of email layout
*
* @param string $htmlContent HTML name of WYSIWYG field to fill
- * @return string HTML for model email boxes
+ * @return string HTML for model email boxes
*/
public function getModelEmailTemplate($htmlContent = 'message')
{
- global $langs;
+ global $websitepage, $langs, $user;
require_once DOL_DOCUMENT_ROOT.'/core/lib/emaillayout.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
- $out = '
';
+
$out .= '';
+
+ $("#blogpost-select").change(function() {
+ var selectedIds = $(this).val();
+ var contentHtml = $(".template-option.selected").data("content");
+
+ updateSelectedPostsContent(contentHtml, selectedIds);
+ });
+
+ function updateSelectedPostsContent(contentHtml, selectedIds) {
+ var csrfToken = "' .newToken().'";
+ $.ajax({
+ type: "POST",
+ url: "/core/ajax/getnews.php",
+ data: {
+ selectedIds: JSON.stringify(selectedIds),
+ token : csrfToken
+ },
+ success: function(response) {
+ var selectedPosts = JSON.parse(response);
+ var subject = $("#sujet").val();
+
+ contentHtml = contentHtml.replace(/__SUBJECT__/g, subject);
+
+ $.ajax({
+ type: "POST",
+ url: "/core/ajax/mailtemplate.php",
+ data: {
+ content: contentHtml,
+ selectedPosts: selectedIds.join(","),
+ token: csrfToken
+ },
+ success: function(response) {
+ jQuery("#'.$htmlContent.'").val(response);
+ var editorInstance = CKEDITOR.instances["'.$htmlContent.'"];
+ if (editorInstance) {
+ editorInstance.setData(response);
+ }
+ },
+ error: function(xhr, status, error) {
+ console.error("An error occurred: " + xhr.responseText);
+ }
+ });
+ },
+ error: function(xhr, status, error) {
+ console.error("An error occurred: " + xhr.responseText);
+ }
+ });
+ }
+ });
+ ';
return $out;
}
diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php
index a5a2200b4ba..c090d999114 100644
--- a/htdocs/core/lib/website.lib.php
+++ b/htdocs/core/lib/website.lib.php
@@ -1528,3 +1528,29 @@ function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modify
}
}
}
+
+/**
+ * Retrieves the details of a news post by its ID.
+ *
+ * @param string $postId The ID of the news post to retrieve.
+ * @return array|int Return array if OK, -1 if KO
+ */
+function getNewsDetailsById($postId)
+{
+ global $db;
+
+ if (empty($postId)) {
+ return -1;
+ }
+
+ $sql = "SELECT p.title, p.description, p.date_creation, p.image
+ FROM ".MAIN_DB_PREFIX."website_page as p
+ WHERE p.rowid = ".(intval($postId));
+
+ $resql = $db->query($sql);
+ if ($resql) {
+ return $db->fetch_array($resql);
+ } else {
+ return -1;
+ }
+}
diff --git a/htdocs/install/doctemplates/maillayout/news.html b/htdocs/install/doctemplates/maillayout/news.html
index 4768a4419db..8ab4a6b8e92 100644
--- a/htdocs/install/doctemplates/maillayout/news.html
+++ b/htdocs/install/doctemplates/maillayout/news.html
@@ -1,6 +1,7 @@
__LAST_NEWS__
__CONTENOFMAILHOLDER__
+
__NEWS_LIST__
diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php
index 0fc7413d9a8..2a839651f1b 100644
--- a/htdocs/theme/eldy/global.inc.php
+++ b/htdocs/theme/eldy/global.inc.php
@@ -3017,7 +3017,6 @@ a.tmenuimage:hover{
text-decoration: none;
}
-
/* To show text of top menu according to option THEME_TOPMENU_DISABLE_IMAGE */
/* Text hidden by default */