From f88506d02c15d8e0cc7bc0f9f72b3c22c9e3463c Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Mon, 18 Sep 2017 17:33:54 +0100
Subject: [PATCH] FIX #5949 log when document is created

---
 apps/maarch_entreprise/lang/en.php | 3 +++
 apps/maarch_entreprise/lang/fr.php | 3 +++
 core/manage_action.php             | 8 +++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/apps/maarch_entreprise/lang/en.php b/apps/maarch_entreprise/lang/en.php
index a89d96073cb..5c4cf3a99bb 100755
--- a/apps/maarch_entreprise/lang/en.php
+++ b/apps/maarch_entreprise/lang/en.php
@@ -2043,3 +2043,6 @@ if (!defined("_NEW_ITEM")) define("_NEW_ITEM", "New");
 if(!defined('_SAVED_CHANGE'))
     define('_SAVED_CHANGE', 'Saved change');
 /** Generic messages **/
+
+if (!defined('_DOC_CREATED_WITH_STATUS'))
+    define('_DOC_CREATED_WITH_STATUS', 'Document created with status');
\ No newline at end of file
diff --git a/apps/maarch_entreprise/lang/fr.php b/apps/maarch_entreprise/lang/fr.php
index 7cce282324c..60872734e60 100755
--- a/apps/maarch_entreprise/lang/fr.php
+++ b/apps/maarch_entreprise/lang/fr.php
@@ -2090,3 +2090,6 @@ if (!defined('_STATUS_UPDATED'))
 if(!defined('_SAVED_CHANGE'))
     define('_SAVED_CHANGE', 'Modification enregistrée');
 /** Generic messages **/
+
+if (!defined('_DOC_CREATED_WITH_STATUS'))
+    define('_DOC_CREATED_WITH_STATUS', 'Document créé avec le statut');
\ No newline at end of file
diff --git a/core/manage_action.php b/core/manage_action.php
index daf3ceef337..f636022f0a5 100755
--- a/core/manage_action.php
+++ b/core/manage_action.php
@@ -141,7 +141,7 @@ if($_POST['req'] == 'valid_form' && !empty($_POST['action_id']) && isset($_POST[
     }
 }
 elseif(trim($_POST['req']) == 'change_status' && !empty($_POST['values']) && !empty($_POST['new_status']) && !empty($_POST['table'])){
-    $stmt = $db->query("select id from status where id = ?", array($_POST['new_status']));
+    $stmt = $db->query("select id, label_status from status where id = ?", array($_POST['new_status']));
     $lineStatus = $stmt->fetchObject();
     if ($lineStatus->id <> '') {
         $arr_id = explode(',', $_POST['values']);
@@ -163,6 +163,12 @@ elseif(trim($_POST['req']) == 'change_status' && !empty($_POST['values']) && !em
                     echo "{status : 1, error_txt : '".addslashes(_ERROR_WITH_STATUS." ".functions::xssafe($query_str))."'}";
                     exit();
                 }
+                require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_history.php");
+                $hist = new history();
+                $hist->add(
+                    $_POST['table'],
+                    $arr_id[$i], 'ACTION#', 'resadd',
+                    _DOC_CREATED_WITH_STATUS . ' : '. $lineStatus->label_status, $_SESSION['config']['databasetype'], 'apps');
             }
         }
         echo json_encode(['status' => 0, 'error_txt' => _STATUS_UPDATED.' : '.functions::xssafe($_POST['new_status']) ]);
-- 
GitLab