Use correct phone for response to discussion
This commit is contained in:
parent
c4bc7d94c1
commit
aee9fc847f
|
@ -250,7 +250,7 @@
|
||||||
$uid = $_GET['id'] ?? false;
|
$uid = $_GET['id'] ?? false;
|
||||||
$dlr = $_GET['dlr'] ?? false;
|
$dlr = $_GET['dlr'] ?? false;
|
||||||
|
|
||||||
if ($uid === false || $dlr ==== false)
|
if ($uid === false || $dlr === false)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,4 +213,16 @@ namespace controllers\internals;
|
||||||
{
|
{
|
||||||
return $this->get_model()->get_since_by_date_for_origin_and_user($id_user, $date, $origin);
|
return $this->get_model()->get_since_by_date_for_origin_and_user($id_user, $date, $origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find destination of last received message for an origin and user
|
||||||
|
* @param int $id_user : User id
|
||||||
|
* @param string $origin : Origin number
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_last_for_origin_and_user (int $id_user, string $origin)
|
||||||
|
{
|
||||||
|
return $this->get_model()->get_last_for_origin_and_user($id_user, $origin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,4 +172,16 @@ namespace controllers\internals;
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find last sended message for a destination and user
|
||||||
|
* @param int $id_user : User id
|
||||||
|
* @param string $destination : Destination number
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_last_for_destination_and_user (int $id_user, string $destination)
|
||||||
|
{
|
||||||
|
return $this->get_model()->get_last_for_destination_and_user($id_user, $destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,9 +70,15 @@ namespace controllers\publics;
|
||||||
{
|
{
|
||||||
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $number);
|
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $number);
|
||||||
|
|
||||||
|
$last_sended = $this->internal_sended->get_last_for_destination_and_user($_SESSION['user']['id'], $number);
|
||||||
|
$last_received = $this->internal_received->get_last_for_origin_and_user($_SESSION['user']['id'], $number);
|
||||||
|
|
||||||
|
$response_number = ($last_received['destination'] ?? $last_sended['origin'] ?? false);
|
||||||
|
|
||||||
$this->render('discussion/show', [
|
$this->render('discussion/show', [
|
||||||
'number' => $number,
|
'number' => $number,
|
||||||
'contact' => $contact,
|
'contact' => $contact,
|
||||||
|
'response_number' => $response_number,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +154,8 @@ namespace controllers\publics;
|
||||||
*
|
*
|
||||||
* @param string $csrf : Le jeton csrf
|
* @param string $csrf : Le jeton csrf
|
||||||
* @param string $_POST['text'] : Le contenu du Sms
|
* @param string $_POST['text'] : Le contenu du Sms
|
||||||
* @param string $_POST['numbers'] : Un tableau avec le numero des gens auxquel envoyer le sms
|
* @param string $_POST['destination'] : Number to send sms to
|
||||||
|
* @param string $_POST['origin'] : Number to send sms with
|
||||||
*
|
*
|
||||||
* @return string : json string Le statut de l'envoi
|
* @return string : json string Le statut de l'envoi
|
||||||
*/
|
*/
|
||||||
|
@ -172,9 +179,10 @@ namespace controllers\publics;
|
||||||
$id_user = $_SESSION['user']['id'];
|
$id_user = $_SESSION['user']['id'];
|
||||||
$at = $now;
|
$at = $now;
|
||||||
$text = $_POST['text'] ?? '';
|
$text = $_POST['text'] ?? '';
|
||||||
$numbers = $_POST['numbers'] ?? false;
|
$destination = $_POST['destination'] ?? false;
|
||||||
|
$origin = $_POST['origin'] ?? false;
|
||||||
|
|
||||||
if (!$numbers)
|
if (!$destination)
|
||||||
{
|
{
|
||||||
$return['success'] = false;
|
$return['success'] = false;
|
||||||
$return['message'] = 'Vous devez renseigner un numéro valide';
|
$return['message'] = 'Vous devez renseigner un numéro valide';
|
||||||
|
@ -183,7 +191,15 @@ namespace controllers\publics;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->internal_scheduled->create($id_user, $at, $text, null, false, $numbers))
|
if (!$origin)
|
||||||
|
{
|
||||||
|
$origin = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Destinations must be an array of number
|
||||||
|
$destinations = [$destination];
|
||||||
|
|
||||||
|
if (!$this->internal_scheduled->create($id_user, $at, $text, $origin, false, $destinations))
|
||||||
{
|
{
|
||||||
$return['success'] = false;
|
$return['success'] = false;
|
||||||
$return['message'] = 'Impossible de créer le Sms';
|
$return['message'] = 'Impossible de créer le Sms';
|
||||||
|
|
|
@ -388,4 +388,31 @@ namespace models;
|
||||||
|
|
||||||
return $this->_run_query($query, $params);
|
return $this->_run_query($query, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find destination of last received message for an origin and user
|
||||||
|
* @param int $id_user : User id
|
||||||
|
* @param string $origin : Origin number
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_last_for_origin_and_user (int $id_user, string $origin)
|
||||||
|
{
|
||||||
|
$query = "
|
||||||
|
SELECT *
|
||||||
|
FROM received
|
||||||
|
WHERE origin = :origin
|
||||||
|
AND destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||||
|
ORDER BY at DESC
|
||||||
|
LIMIT 0,1
|
||||||
|
";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'origin' => $origin,
|
||||||
|
'id_user' => $id_user,
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->_run_query($query, $params);
|
||||||
|
|
||||||
|
return ($result[0] ?? []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,5 +300,33 @@ namespace models;
|
||||||
|
|
||||||
return $this->_run_query($query, $params);
|
return $this->_run_query($query, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find last sended message for a destination and user
|
||||||
|
* @param int $id_user : User id
|
||||||
|
* @param string $destination : Destination number
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_last_for_destination_and_user (int $id_user, string $destination)
|
||||||
|
{
|
||||||
|
$query = "
|
||||||
|
SELECT *
|
||||||
|
FROM sended
|
||||||
|
WHERE destination = :destination
|
||||||
|
AND origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||||
|
ORDER BY at DESC
|
||||||
|
LIMIT 0,1
|
||||||
|
";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'destination' => $destination,
|
||||||
|
'id_user' => $id_user,
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->_run_query($query, $params);
|
||||||
|
|
||||||
|
return ($result[0] ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,10 @@
|
||||||
<div class="discussion-message message-input">
|
<div class="discussion-message message-input">
|
||||||
<form class="send-message-discussion" action="<?php $this->s(\descartes\Router::url('Discussion', 'send', ['csrf' => $_SESSION['csrf']])); ?>" method="POST">
|
<form class="send-message-discussion" action="<?php $this->s(\descartes\Router::url('Discussion', 'send', ['csrf' => $_SESSION['csrf']])); ?>" method="POST">
|
||||||
<textarea name="text" placeholder="Envoyer un message..."></textarea>
|
<textarea name="text" placeholder="Envoyer un message..."></textarea>
|
||||||
<input type="hidden" name="numbers[]" value="<?php $this->s($number); ?>" />
|
<input type="hidden" name="destination" value="<?php $this->s($number); ?>" />
|
||||||
|
<?php if ($response_number ) { ?>
|
||||||
|
<input type="hidden" name="origin" value="<?php $this->s($response_number); ?>" />
|
||||||
|
<?php } ?>
|
||||||
<button class="btn" ><span class="fa fa-fw fa-send-o"></span> Envoyer</button>
|
<button class="btn" ><span class="fa fa-fw fa-send-o"></span> Envoyer</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue