2019-10-29 14:57:13 +01:00
< ? php
//Template dashboard
$this -> render ( 'incs/head' , [ 'title' => 'Discussions - Show All' ])
?>
< div id = " wrapper " >
< ? php
$this -> render ( 'incs/nav' , [ 'page' => 'discussions' ])
?>
< div id = " page-wrapper " >
< div class = " container-fluid " >
<!-- Page Heading -->
< div class = " row " >
< div class = " col-lg-12 " >
< h1 class = " page-header " >
2019-11-29 03:07:39 +01:00
Discussion < small >< ? php $this -> s ( $contact ? $contact [ 'name' ] . ' (' . \controllers\internals\Tool :: phone_format ( $number ) . ')' : \controllers\internals\Tool :: phone_format ( $number )); ?> </small>
2019-10-29 14:57:13 +01:00
</ h1 >
< ol class = " breadcrumb " >
< li >
2019-11-07 17:52:33 +01:00
< i class = " fa fa-dashboard " ></ i > < a href = " <?php echo \ descartes \R outer::url('Dashboard', 'show'); ?> " > Dashboard </ a >
2019-10-29 14:57:13 +01:00
</ li >
< li >
2019-11-07 17:52:33 +01:00
< i class = " fa fa-comments-o " ></ i > < a href = " <?php echo \ descartes \R outer::url('Discussion', 'list'); ?> " > Discussions </ a >
2019-10-29 14:57:13 +01:00
</ li >
< li class = " active " >
2019-11-29 03:07:39 +01:00
< ? php $this -> s ( \controllers\internals\Tool :: phone_format ( $number )); ?>
2019-10-29 14:57:13 +01:00
</ li >
</ ol >
</ div >
</ div >
<!-- /. row -->
< div class = " row " >
< div class = " col-lg-12 discussion-container " >
2021-04-13 02:01:03 +02:00
< div class = " text-center " id = " load-message-spinner " >< i class = " fa fa-spinner fa-spin " ></ i ></ div >
2019-10-29 14:57:13 +01:00
</ div >
< div class = " col-lg-12 message-input-container " >
< div class = " discussion-message message-input " >
2019-11-10 17:32:59 +01:00
< form class = " send-message-discussion " action = " <?php $this->s ( \ descartes \R outer::url('Discussion', 'send', ['csrf' => $_SESSION['csrf'] ])); ?> " method = " POST " >
< textarea name = " text " placeholder = " Envoyer un message... " ></ textarea >
2020-01-11 17:27:07 +01:00
< input type = " hidden " name = " destination " value = " <?php $this->s ( $number ); ?> " />
2020-03-04 04:41:31 +01:00
< ? php if ( $response_phone ) { ?>
< input type = " hidden " name = " id_phone " value = " <?php $this->s ( $response_phone['id'] ); ?> " />
2020-01-11 17:27:07 +01:00
< ? php } ?>
2021-04-06 20:52:07 +02:00
< ? php if ( $_SESSION [ 'user' ][ 'settings' ][ 'mms' ] ? ? false ) { ?>
< input name = " medias[] " type = " file " multiple />
< ? php } ?>
2019-10-29 14:57:13 +01:00
< button class = " btn " >< span class = " fa fa-fw fa-send-o " ></ span > Envoyer </ button >
</ form >
</ div >
</ div >
</ div >
</ div >
</ div >
</ div >
< script >
jQuery ( document ) . ready ( function () {
2021-04-16 17:11:24 +02:00
//List of messages already loaded
var cachedMessages = {};
/**
2019-10-29 14:57:13 +01:00
* Cette fonction vérifie régulièrement les sms pour mettre à jour l ' affichage
*/
function getmessages ()
{
2021-04-13 02:01:03 +02:00
ajaxTransactionId = Date . now ();
2021-04-16 17:11:24 +02:00
var first_load = true ;
url = HTTP_PWD + " /discussion/getmessage/<?php echo htmlspecialchars(urlencode( $number )); ?>/ " + ajaxTransactionId ;
var newMessages = false ;
2021-04-13 02:01:03 +02:00
jQuery . getJSON ( url , function ( data ) {
2019-10-29 14:57:13 +01:00
if ( data . transaction_id != ajaxTransactionId )
{
return false ;
2021-04-13 02:01:03 +02:00
}
2019-10-29 14:57:13 +01:00
2021-04-13 02:01:03 +02:00
jQuery ( '.discussion-container #load-message-spinner' ) . remove ();
jQuery ( '.discussion-container #send-message-spinner' ) . remove ();
2019-10-29 14:57:13 +01:00
2021-04-13 02:33:30 +02:00
//We also remove all in-progress messages because they are added again in the new response if not sended yet, and if sended they should not appear in double
jQuery ( '.discussion-container .message-in-progress-container' ) . remove ();
2019-10-29 14:57:13 +01:00
$ . each ( data . messages , function ( key , message ) {
2021-04-16 17:11:24 +02:00
//If message already loaded, continue
if ( message . uid in cachedMessages )
{
if ( cachedMessages [ message . uid ][ 'type' ] == 'sended' )
{
if ( message . status != cachedMessages [ message . uid ][ 'status' ])
{
cachedMessages [ message . uid ] = message ;
var htmlStatus = ( message . status == 'delivered' ? '<span class="message-status fa fa-check-circle fa-fw text-success"></span>' : ( message . status == 'failed' ? '<span class="message-status fa fa-times-circle fa-fw text-danger"></span>' : '<span class="message-status fa fa-clock-o fa-fw text-info"></span>' ));
jQuery ( '.discussion-container #' + message . uid + " .message-status " ) . replaceWith ( htmlStatus );
}
}
return ;
}
//Add the message to the list of already receiveds once
cachedMessages [ message . uid ] = message ;
newMessages = true ;
2019-10-29 14:57:13 +01:00
2019-11-11 04:05:26 +01:00
< ? php if ( $_SESSION [ 'user' ][ 'settings' ][ 'detect_url' ]) { ?>
2019-10-29 14:57:13 +01:00
//On ajoute la detection de lien dans le texte du message
message . text = Autolinker . link ( message . text , { newWindow : true });
2021-03-21 18:29:23 +01:00
< ? php } ?>
2019-10-29 14:57:13 +01:00
2021-03-22 17:08:29 +01:00
var medias = message . medias . map (( mediaUrl , index ) => {
var extension = mediaUrl . split ( '.' ) . pop ();
if ([ 'jpg' , 'jpeg' , 'png' , 'gif' ] . includes ( extension ))
{
return '<div class="discussion-message-media"><a href="' + mediaUrl + '" target="_blank"><img src="' + mediaUrl + '"/></a></div>' ;
}
2021-04-13 02:07:47 +02:00
else if ([ 'webm' , 'ogv' , 'mp4' ] . includes ( extension ))
2021-04-13 02:01:03 +02:00
{
return '<video controls class="discussion-message-media"><source src="' + mediaUrl + '"/></video>' ;
}
2021-04-13 02:07:47 +02:00
else if ([ 'wav' , 'ogg' , 'mp3' ] . includes ( extension ))
{
return '<audio controls class="discussion-message-media"><source src="' + mediaUrl + '"/></audio>' ;
}
2021-03-22 17:08:29 +01:00
else
{
2021-03-27 01:15:09 +01:00
return '<div class="discussion-message-media"><a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + ( Number ( index ) + 1 ) + '</a></div>' ;
2021-03-22 17:08:29 +01:00
}
});
var medias_html = '<div class="discussion-message-medias">' + medias . join ( '' ) + '</div>' ;
2019-10-29 14:57:13 +01:00
switch ( message . type )
2021-03-22 17:08:29 +01:00
{
2019-10-29 14:57:13 +01:00
case 'received' :
var texte = '' +
2021-04-16 17:11:24 +02:00
'<div class="clearfix message-container" id="' + message . uid + '">' +
2019-10-29 14:57:13 +01:00
'<div class="discussion-message message-received">' +
2021-04-16 20:20:19 +02:00
'<div class="discussion-message-text">' + message . text . replace ( / \n / g , " <br> " ) + '</div>' +
2021-03-27 01:15:09 +01:00
medias_html +
2021-03-21 18:29:23 +01:00
'<div class="discussion-message-date">' + message . date + '</div>' +
2019-10-29 14:57:13 +01:00
'</div>' +
'</div>' ;
2021-04-16 17:11:24 +02:00
if ( ! first_load ) //If new message received and not first time loading
2019-10-29 14:57:13 +01:00
{
playReceptionSound ();
}
break ;
case 'sended' :
var texte = '' +
2021-04-16 17:11:24 +02:00
'<div class="clearfix message-container" id="' + message . uid + '">' +
2019-10-29 14:57:13 +01:00
'<div class="discussion-message message-sended">' +
2021-04-16 20:20:19 +02:00
'<div class="discussion-message-text">' + message . text . replace ( / \n / g , " <br> " ) + '</div>' +
2021-03-22 17:08:29 +01:00
medias_html +
2021-04-16 17:11:24 +02:00
'<div class="discussion-message-date">' + message . date + ' ' + ( message . status == 'delivered' ? '<span class="message-status fa fa-check-circle fa-fw text-success"></span>' : ( message . status == 'failed' ? '<span class="message-status fa fa-times-circle fa-fw text-danger"></span>' : '<span class="message-status fa fa-clock-o fa-fw text-info"></span>' )) + '</div>' +
2019-10-29 14:57:13 +01:00
'</div>' +
'</div>' ;
break ;
case 'inprogress' :
var texte = '' +
2021-04-16 17:11:24 +02:00
'<div class="clearfix message-container message-in-progress-container" id="' + message . uid + '">' +
2019-10-29 14:57:13 +01:00
'<div class="discussion-message message-sended">' +
'<div class="message-in-progress-hover"><i class="fa fa-spinner fa-spin"></i></div>' +
2021-04-16 20:20:19 +02:00
'<div class="discussion-message-text">' + message . text . replace ( / \n / g , " <br> " ) + '</div>' +
2021-03-22 17:08:29 +01:00
medias_html +
2019-10-29 14:57:13 +01:00
'<div class="discussion-message-date">' + message . date + '</div>' +
'</div>' +
'</div>' ;
break ;
default :
var texte = '' ;
break ;
}
jQuery ( '.discussion-container' ) . append ( texte );
2021-04-13 02:01:03 +02:00
});
2021-04-16 17:11:24 +02:00
if ( newMessages ) {
2021-04-13 02:01:03 +02:00
scrollDownDiscussion ( first_load );
}
2019-10-29 14:57:13 +01:00
});
}
/**
* Cette fonction permet de fixer la taille de la fenetre de discussion
*/
function fullHeightDiscussion ()
{
var containerPosition = jQuery ( '.discussion-container' ) . position ();
var windowHeight = jQuery ( window ) . height ();
var messageInputContainer = jQuery ( '.message-input-container' ) . outerHeight ();
var footerHeight = jQuery ( 'footer' ) . outerHeight ();
2020-09-23 03:02:13 +02:00
var containerHeight = Math . floor ( windowHeight - ( containerPosition . top + messageInputContainer ) - 20 ); //-20 px for aesthetic
2019-10-29 14:57:13 +01:00
jQuery ( '.discussion-container' ) . outerHeight ( containerHeight );
}
fullHeightDiscussion ();
jQuery ( window ) . on ( 'resize' , function () {
fullHeightDiscussion ();
});
var getmessagesInterval = setInterval ( getmessages , 2500 );
});
</ script >
< ? php
$this -> render ( 'incs/footer' );