From 34c4aa270ad211493b06a1ef24734f4de784e445 Mon Sep 17 00:00:00 2001
From: "henri.queneau" <henri.queneau@maarch.org>
Date: Mon, 13 Mar 2017 10:22:35 +0100
Subject: [PATCH] FEAT #5288 dev notes

---
 apps/maarch_entreprise/lang/en.php      |   1 +
 apps/maarch_entreprise/lang/fr.php      |   1 +
 apps/maarch_entreprise/loadNoteList.php |  65 ++++++-
 modules/notes/lang/en.php               |   3 +-
 modules/notes/lang/fr.php               |   3 +-
 modules/notes/notes.php                 | 248 ++++++++++++++----------
 modules/notes/notes_ajax_content.php    |   8 +-
 7 files changed, 216 insertions(+), 113 deletions(-)

diff --git a/apps/maarch_entreprise/lang/en.php b/apps/maarch_entreprise/lang/en.php
index ff8596e57cc..1d9e8799bf0 100644
--- a/apps/maarch_entreprise/lang/en.php
+++ b/apps/maarch_entreprise/lang/en.php
@@ -1147,6 +1147,7 @@ if (! defined("_STATUS_UPDATED"))    define("_STATUS_UPDATED", "Updated status")
 
 if (!defined("_QUICKLAUNCH")) define("_QUICKLAUNCH", "Short cut");
 if (!defined("_SHOW_DETAILS_DOC")) define("_SHOW_DETAILS_DOC", "See the document details");
+if (!defined("_VISIBLEBY")) define("_VISIBLEBY", "Visible by");
 if (!defined("_VIEW_DOC_FULL")) define("_VIEW_DOC_FULL", "see the document");
 if (!defined("_DETAILS_DOC_FULL")) define("_DETAILS_DOC_FULL", "See the document card");
 if (!defined("_IDENTIFIER")) define("_IDENTIFIER", "Reference");
diff --git a/apps/maarch_entreprise/lang/fr.php b/apps/maarch_entreprise/lang/fr.php
index 481a42312d2..b98bbae2e0b 100755
--- a/apps/maarch_entreprise/lang/fr.php
+++ b/apps/maarch_entreprise/lang/fr.php
@@ -802,6 +802,7 @@ if (!defined("_DIRECT_CONTACT")) define("_DIRECT_CONTACT","Prise de contact dire
 if (!defined("_NO_ANSWER")) define("_NO_ANSWER","Pas de réponse");
 if (!defined("_ANSWER")) define("_ANSWER","Réponse");
 if (!defined("_DETAILS")) define("_DETAILS", "Fiche détaillée");
+if (!defined("_VISIBLEBY")) define("_VISIBLEBY", "Visible par");
 if (!defined("_DOWNLOAD")) define("_DOWNLOAD", "Télécharger le courrier");
 if (!defined("_SEARCH_RESULTS")) define("_SEARCH_RESULTS", "Résultat de la recherche");
 
diff --git a/apps/maarch_entreprise/loadNoteList.php b/apps/maarch_entreprise/loadNoteList.php
index b7506411e23..332805ab7e6 100644
--- a/apps/maarch_entreprise/loadNoteList.php
+++ b/apps/maarch_entreprise/loadNoteList.php
@@ -30,6 +30,9 @@
 */
 
 require_once('core/class/class_core_tools.php');
+require_once "modules" . DIRECTORY_SEPARATOR . "notes" . DIRECTORY_SEPARATOR
+    . "class" . DIRECTORY_SEPARATOR
+    . "class_modules_tools.php";
 $Core_Tools = new core_tools;
 $Core_Tools->load_lang();
 $Core_Tools->test_user();
@@ -91,31 +94,85 @@ if (isset($_REQUEST['identifier'])) {
                 $fetch = '';
                 while ($return_db = $stmt->fetchObject()) {
                     // get lastname and firstname for user_id
+                  //var_dump($return_db);
                     $stmt2 = $db->query("SELECT lastname, firstname FROM users WHERE user_id =?", array($return_db->user_id));
                     while ($user_db = $stmt2->fetchObject()) {
                         $lastname = $user_db->lastname;
                         $firstname = $user_db->firstname;
                     }
-
+                    $stmt3 = $db->query("SELECT notes.id as id, identifier, user_id, note_text, item_id, entity_label FROM notes, note_entities, entities WHERE identifier = ? AND note_id = notes.id AND entities.entity_id = note_entities.item_id and notes.id = ?", array($_REQUEST['identifier'], $return_db->id));
+                    $entity_label = '';
+                    $Tabentity = [];
+                    while ($entity = $stmt3->fetchObject()) {
+                        $Tabentity[] = $entity->entity_label;
+                        $item_id = $entity->id;
+                        $entity_label = $entity->entity_label;
+                        }
                     $return .= '<tr>';
                         $return .= '<td style="background: transparent; padding-left:30px; padding-right:30px; border: 1px dashed rgb(200, 200, 200);">';
                             // $return .= '<blockquote style="padding: 1px;">';
                                 $return .= '<div style="text-align: right; background-color: rgb(230, 230, 230); padding: 2px;">';
-                                    $return .= ucfirst(_BY) . ' : ';
+                                    $allEntity = '';
+                                      foreach ($Tabentity as $value){
+                                        $allEntity .= $value." / ";
+                                      } 
+                                      $notes_tools = new notes();
+                                      $noteEntities = $notes_tools->getNotesEntities($return_db->id);
+                                      $tabEntityLabel = [];
+                                      $tabEntityId = [];
+                                      $allEntities = '';
+                                      $allEntitiesId = '';
+
+                                      foreach($noteEntities as $value){
+                                          $tabEntityLabel[] = $value->entity_label;
+                                          $tabEntityId[] = $value->entity_id;
+                                      }
+
+                                      if(!empty($tabEntityLabel)){
+                                          $allEntities = implode(', ',$tabEntityLabel);
+                                          $allEntitiesId = implode(', ',$tabEntityId);
+                                      }
+
                                     $return .= functions::xssafe($firstname) . ' ' . functions::xssafe($lastname);
                                     $return .= ', ';
                                     $return .= functions::xssafe($Core_Tools->format_date_db($return_db->date_note));
+
+                                    if($allEntities != ''){
+
+                                      $return .= '<i title="'.$allEntities.'" style="cursor:pointer;width:35em;text-overflow: ellipsis;color:red;clear:both;white-space: nowrap;overflow: hidden;">';
+                                      $return .= ' (note restreinte)';
+                                      $return .= '</i>';
+
+                                    }
+                                    
                                 $return .= '</div>';
+
                                 // $return .= '<br />';
+                                if($entity_label != ''){
+
+                                    $return .= '<div style="padding-top:2px;padding-bottom:2px;color:red;">';
+                                    $note_text = str_replace(array("\r", "\n"), array("<br />", "<br />"), functions::xssafe($return_db->note_text));
+                                    $return .= str_replace('<br /><br />', '<br />', $note_text);
+                                    $return .= '</div>';
+                                    $return .= '<div style="padding-top:2px;padding-bottom:2px;">';
+                                    $return .= '<div style="cursor:pointer;width:250px;text-overflow: ellipsis;color:red;clear:both;white-space: nowrap;overflow: hidden;"><i title="'.$allEntities.'" >'._RESTRICTED_SERVICES.$allEntitiesId.'</i></div>';
+                                  $return .= '</div>';
+
+                                  }else{
+
                                 $return .= '<div style="padding-top:2px;padding-bottom:2px;">';
                                     $note_text = str_replace(array("\r", "\n"), array("<br />", "<br />"), functions::xssafe($return_db->note_text));
                                     $return .= str_replace('<br /><br />', '<br />', $note_text);
-                                $return .= '</div>';
+                                    $return .= '</div>';
+
+                                  }
+
+
                             // $return .= '</blockquote>';
                         $return .= '</td>';
                     $return .= '</tr>';
                 }
-            $return .= '</table>';
+                $return .= '</table>';
             $return .= '<br />';
         $return .= '</div>';
     $return .= '</td>';
diff --git a/modules/notes/lang/en.php b/modules/notes/lang/en.php
index a670f39d12b..284a556906b 100644
--- a/modules/notes/lang/en.php
+++ b/modules/notes/lang/en.php
@@ -18,7 +18,8 @@
  *   You should have received a copy of the GNU General Public License
  *    along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
  */
-
+if (!defined("_RESTRICTED_SERVICES")) define("_RESTRICTED_SERVICES", "Service(s) restricted : ");
+if (!defined("_VISIBLEBY")) define("_VISIBLEBY", "Visible by");
 if (!defined("_ADD_NOTE"))
     define("_ADD_NOTE","Add a note");
 if (!defined("_READ"))
diff --git a/modules/notes/lang/fr.php b/modules/notes/lang/fr.php
index 25350af2d17..1aa9bc60f1e 100644
--- a/modules/notes/lang/fr.php
+++ b/modules/notes/lang/fr.php
@@ -18,7 +18,8 @@
  *   You should have received a copy of the GNU General Public License
  *    along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
  */
-
+if (!defined("_RESTRICTED_SERVICES")) define("_RESTRICTED_SERVICES", "Restreint au(x) service(s): ");
+if (!defined("_VISIBLEBY")) define("_VISIBLEBY", "Visible by");
 if (!defined("_ADD_NOTE"))
     define("_ADD_NOTE","Ajouter une note");
 if (!defined("_READ"))
diff --git a/modules/notes/notes.php b/modules/notes/notes.php
index 5edccd3303d..5dd131ee3d0 100644
--- a/modules/notes/notes.php
+++ b/modules/notes/notes.php
@@ -117,7 +117,7 @@ if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&st
         
     //Fields
         array_push($select[NOTES_TABLE], "id", "identifier", "date_note", "user_id", "note_text", "note_text as note_short", "coll_id");    //Notes
-        array_push($select[USERS_TABLE], "user_id", "firstname", "lastname");           //Users
+        array_push($select[USERS_TABLE], "user_id", "firstname", "lastname","lastname as visibleBy");           //Users
         
     //Where clause
         $where_tab = array();
@@ -144,127 +144,162 @@ if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&st
     
     //Request
 
-		$tabNotes=$request->PDOselect(
+        $tabNotes=$request->PDOselect(
             $select, $where, $arrayPDO, $orderstr,
             $_SESSION['config']['databasetype'], "500", true, NOTES_TABLE, USERS_TABLE,
             "user_id"
         );
         
-		//LGI UPDATE
-		$arrayToUnset = array();
+        //LGI UPDATE
+        $arrayToUnset = array();
 
-		for ($indNotes1 = 0; $indNotes1 < count($tabNotes); $indNotes1 ++ ) {
-			for ($indNotes2 = 0; $indNotes2 < count($tabNotes[$indNotes1]); $indNotes2 ++) {
-				foreach (array_keys($tabNotes[$indNotes1][$indNotes2]) as $value) {
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "id") {
-						$tabNotes[$indNotes1][$indNotes2]["id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["label"] = 'ID';
-						$tabNotes[$indNotes1][$indNotes2]["size"] = $sizeSmall;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = true;
-						$indNotes1d = $tabNotes[$indNotes1][$indNotes2]['value'];
-						if (!$notes_tools->isUserNote(
-							$tabNotes[$indNotes1][$indNotes2]['value'], 
-							$_SESSION['user']['UserId'], 
-							$_SESSION['user']['primaryentity']['id']
-							)
-						) {
-							//unset($tabNotes[$indNotes1]);
-							//echo 'sort ' . $indNotes1 . '<br>';
-							array_push($arrayToUnset, $indNotes1);
-						} else {
-							//echo 'garde ' . $indNotes1 . '<br>';
-						}
-					}
-				}
-			}
-		}
+        for ($indNotes1 = 0; $indNotes1 < count($tabNotes); $indNotes1 ++ ) {
+            for ($indNotes2 = 0; $indNotes2 < count($tabNotes[$indNotes1]); $indNotes2 ++) {
+                foreach (array_keys($tabNotes[$indNotes1][$indNotes2]) as $value) {
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "id") {
+                        $tabNotes[$indNotes1][$indNotes2]["id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = 'ID';
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = $sizeSmall;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
+                        $indNotes1d = $tabNotes[$indNotes1][$indNotes2]['value'];
+                                               
+                        if (!$notes_tools->isUserNote(
+                            $tabNotes[$indNotes1][$indNotes2]['value'], 
+                            $_SESSION['user']['UserId'], 
+                            $_SESSION['user']['primaryentity']['id']
+                            )
+                        ) {
+                            //unset($tabNotes[$indNotes1]);
+                            //echo 'sort ' . $indNotes1 . '<br>';
+                            array_push($arrayToUnset, $indNotes1);
+                        } else {
+                            //echo 'garde ' . $indNotes1 . '<br>';
+                        }
+                    }
+                }
+            }
+        }
+
+        //var_dump($tabNotes);
 
-		for ($cptUnset=0;$cptUnset<count($arrayToUnset);$cptUnset++ ) {
-			unset($tabNotes[$arrayToUnset[$cptUnset]]);
-		}
+        for ($cptUnset=0;$cptUnset<count($arrayToUnset);$cptUnset++ ) {
+            unset($tabNotes[$arrayToUnset[$cptUnset]]);
+        }
         // array_multisort($tabNotes, SORT_DESC);
         $tabNotes = array_merge($tabNotes);
-		
-		// $request->show_array($tabNotes);
-		for ($indNotes1 = 0; $indNotes1 < count($tabNotes); $indNotes1 ++ ) {
-			for ($indNotes2 = 0; $indNotes2 < count($tabNotes[$indNotes1]); $indNotes2 ++) {
-				foreach (array_keys($tabNotes[$indNotes1][$indNotes2]) as $value) {
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "id") {
-						$tabNotes[$indNotes1][$indNotes2]["id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["label"] = 'ID';
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 1;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+        
+        // $request->show_array($tabNotes);
+        for ($indNotes1 = 0; $indNotes1 < count($tabNotes); $indNotes1 ++ ) {
+            for ($indNotes2 = 0; $indNotes2 < count($tabNotes[$indNotes1]); $indNotes2 ++) {
+                foreach (array_keys($tabNotes[$indNotes1][$indNotes2]) as $value) {
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "id") {
+                        $tabNotes[$indNotes1][$indNotes2]["id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = 'ID';
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 1;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = false;
+                        $tabNotes[$indNotes1][$indNotes2]["order"] = "id";
+                        $indNotes1d = $tabNotes[$indNotes1][$indNotes2]['value'];
+                    }
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "user_id") {
+                        $tabNotes[$indNotes1][$indNotes2]["user_id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _ID;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 5;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
                         $tabNotes[$indNotes1][$indNotes2]["show"] = false;
-						$tabNotes[$indNotes1][$indNotes2]["order"] = "id";
-						$indNotes1d = $tabNotes[$indNotes1][$indNotes2]['value'];
-					}
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "user_id") {
-						$tabNotes[$indNotes1][$indNotes2]["user_id"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["label"] = _ID;
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 5;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = false;
                         $tabNotes[$indNotes1][$indNotes2]["order"] = "user_id";
-					}
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "lastname") {
-						$tabNotes[$indNotes1][$indNotes2]['value'] = $request->show_string(
-							$tabNotes[$indNotes1][$indNotes2]['value']
-						);
-						$tabNotes[$indNotes1][$indNotes2]["lastname"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["label"] = _LASTNAME;
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 5;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = true;
+                    }
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "lastname") {
+                        $tabNotes[$indNotes1][$indNotes2]['value'] = $request->show_string(
+                            $tabNotes[$indNotes1][$indNotes2]['value']
+                        );
+                        $tabNotes[$indNotes1][$indNotes2]["lastname"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _LASTNAME;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 5;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
                         $tabNotes[$indNotes1][$indNotes2]["order"] = "lastname";
-					}
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "date_note") {
-						$tabNotes[$indNotes1][$indNotes2]["date_note"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                    }
+                    //var_dump($tabNotes[$indNotes1][$indNotes2]);
+                    
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "date_note") {
+                        $tabNotes[$indNotes1][$indNotes2]["date_note"] = $tabNotes[$indNotes1][$indNotes2]['value'];
                         $tabNotes[$indNotes1][$indNotes2]["value"] = $core_tools->format_date_db($tabNotes[$indNotes1][$indNotes2]['value'], false, '', true);
-						$tabNotes[$indNotes1][$indNotes2]["label"] = _DATE;
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 5;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = true;
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _DATE;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 5;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
                         $tabNotes[$indNotes1][$indNotes2]["order"] = "date_note";
-					}
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "firstname") {
-						$tabNotes[$indNotes1][$indNotes2]["firstname"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["label"] = _FIRSTNAME;
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 5;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = true;
+                    }
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "firstname") {
+                        $tabNotes[$indNotes1][$indNotes2]["firstname"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _FIRSTNAME;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 5;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
                         $tabNotes[$indNotes1][$indNotes2]["order"] = "firstname";
-					}
-					if ($tabNotes[$indNotes1][$indNotes2][$value] == "note_text") {
-						//$tabNotes[$indNotes1][$indNotes2]["note_text"] = $tabNotes[$indNotes1][$indNotes2]['value'];
-						$tabNotes[$indNotes1][$indNotes2]["note_text"] = $request->cut_string($request->show_string($tabNotes[$indNotes1][$indNotes2]['value']), $cutString);
-						$tabNotes[$indNotes1][$indNotes2]["label"] = _NOTES;
-						$tabNotes[$indNotes1][$indNotes2]["size"] = 20;
-						$tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["align"] = "left";
-						$tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
-						$tabNotes[$indNotes1][$indNotes2]["show"] = true;
+                    }
+                    if ($tabNotes[$indNotes1][$indNotes2][$value] == "note_text") {
+                        //$tabNotes[$indNotes1][$indNotes2]["note_text"] = $tabNotes[$indNotes1][$indNotes2]['value'];
+                        $tabNotes[$indNotes1][$indNotes2]["note_text"] = $request->cut_string($request->show_string($tabNotes[$indNotes1][$indNotes2]['value']), $cutString);
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _NOTES;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 4;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
                         $tabNotes[$indNotes1][$indNotes2]["order"] = "note_text";
-					}
-				}
-			}
-		}
-		
+                    }
+
+                    if($tabNotes[$indNotes1][$indNotes2][$value] == "visibleby")
+                    {
+
+                        $noteEntities = $notes_tools->getNotesEntities($indNotes1d);
+                        $tabEntityLabel = [];
+                        $tabEntityId = [];
+                        $allEntities = '';
+                        $allEntitiesId = '';
+
+                        foreach($noteEntities as $value){
+                            $tabEntityLabel[] = $value->entity_label;
+                            $tabEntityId[] = $value->entity_id;
+                        }
+
+                        if(!empty($tabEntityLabel)){
+                            $allEntities = implode(', ',$tabEntityLabel);
+                            $allEntitiesId = implode(', ',$tabEntityId);
+                        }
+                        
+
+                        $tabNotes[$indNotes1][$indNotes2]['value'] = '<div style="cursor:pointer;width:250px;text-overflow: ellipsis;color:red;clear:both;white-space: nowrap;overflow: hidden;"><i title="'.$allEntities.'" >'.$allEntitiesId.'</i></div>';
+                        $tabNotes[$indNotes1][$indNotes2]["label"] = _VISIBLEBY;
+                        $tabNotes[$indNotes1][$indNotes2]["size"] = 5;
+                        $tabNotes[$indNotes1][$indNotes2]["label_align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["align"] = "left";
+                        $tabNotes[$indNotes1][$indNotes2]["valign"] = "bottom";
+                        $tabNotes[$indNotes1][$indNotes2]["show"] = true;
+
+                    }
+                }
+            }
+        }
+        //var_dump($tabNotes);
         //List
-        $listKey = 'id';                                                                    //Clé de la liste
-        $paramsTab = array();                                                               //Initialiser le tableau de paramètres
+        $listKey = 'id';                                                                    //Clé de la liste
+        $paramsTab = array();                                                               //Initialiser le tableau de paramètres
         $paramsTab['bool_sortColumn'] = true;                                               //Affichage Tri
         $paramsTab['pageTitle'] ='';                                                        //Titre de la page
         $paramsTab['bool_bigPageTitle'] = false;                                            //Affichage du titre en grand
@@ -307,8 +342,9 @@ if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) $parameters .= '&st
         //Output
         $status = 0;
         //$content = $list->showList($tab, $paramsTab, $listKey);
+        //var_dump($tabNotes);
         $content = $list->showList($tabNotes, $paramsTab, $listKey);
-        // $debug = $list->debug();
+         //$debug = $list->debug();
 
     echo "{status : " . $status . ", content : '" . addslashes($debug.$content) . "', error : '" . addslashes($error) . "'}";
 }
diff --git a/modules/notes/notes_ajax_content.php b/modules/notes/notes_ajax_content.php
index 071c6080704..ff52b909307 100644
--- a/modules/notes/notes_ajax_content.php
+++ b/modules/notes/notes_ajax_content.php
@@ -287,10 +287,16 @@ switch ($mode) {
                         }
                     } else if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == "document") {
                         if (!empty($id) && isset($_REQUEST['entities_chosen']) && !empty($_REQUEST['entities_chosen'])){
+                        /*show restricted services*/
+                        $allEntity = '';
+                        foreach ($_REQUEST['entities_chosen'] as $value){
 
+                            $allEntity .= $value." | ";
+
+                        }
                             $hist->add(
                                     $table, $identifier, "UP", 'folderup', _ADDITION_NOTE_PRIVATE . _ON_DOC_NUM
-                                    . $identifier . ' (' . $id . ')',
+                                    . $identifier . ' (' . $id . ')'._VISIBLEBY.' '.$allEntity,
                                     $_SESSION['config']['databasetype'], 'notes'
                                 );
                         }else{
-- 
GitLab