If we are trying to create a new conversation */ if (Tools::isLogged() && isset($_POST['dest']) && isset($_POST['message']) && isset($_POST['titre'])) { $destinataires = $_POST['dest']; $message = $_POST['message']; $titre = $_POST['titre']; $idconversation = $database->newConversation($titre); // get the id of the newly created conversation foreach ($destinataires as $destinataire) { // for each destinataire, add him to table participants $database->addMPParticipants($idconversation, $destinataire, true); } $database->addMPParticipants($idconversation, $user->getid(), false); // adding ourselves $database->newMP($user->getid(), $idconversation, $message); // adding the first message to the list of mps $conversations = $database->getConversationsForUser($user->getid()); // finally, get the new list of conversations } Tools::callTwig('mp.twig', array('connected' => Tools::isLogged(), 'user' => $user, 'conversations' => getConversations($conversations, $user))); /* get proper conversation objects for our user */ function getConversations($conversations, $user) { $mpsobj = array(); foreach ($conversations as $conversation) { $mpsobj[] = new Conversation($conversation['idconversation'], $user); } return $mpsobj; }
</form> <div> <!-- create-message-block --> <?php } if ($mode == 'details') { include 'includes/message-details.php'; } else { $own = getUserData($_SESSION['uid']); $own_photo = $own['photo']; ?> <div class="inboxs-messages"> <?php $myconversations = getConversations($_SESSION['uid']); if (!empty($myconversations)) { foreach ($myconversations as $ix => $conversation) { $conversation_id = $conversation['com_id']; if ($conversation['recipient'] == $_SESSION['uid']) { $nextuser = $conversation['sender']; } else { $nextuser = $conversation['recipient']; } ?> <?php $u = getUserData($nextuser); getLastMessage($conversation_id, $nextuser, 'ASC'); // if(!empty(getLastMessage($conversation_id,$nextuser,'ASC'))){ ?> <div class="message-item odd" data-id="<?php