2018-12-20 07:21:32 +01:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
Portions created by the Initial Developer are Copyright (C) 2016-2018
|
|
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//includes
|
|
|
|
|
require_once "root.php";
|
|
|
|
|
require_once "resources/require.php";
|
|
|
|
|
require_once "resources/check_auth.php";
|
|
|
|
|
|
|
|
|
|
//check permissions
|
|
|
|
|
if (!permission_exists('message_view')) {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
|
|
|
|
//get number of messages to load
|
|
|
|
|
$number = preg_replace('{[\D]}', '', $_GET['number']);
|
|
|
|
|
|
|
|
|
|
//set refresh flag
|
|
|
|
|
$refresh = $_GET['refresh'] == 'true' ? true : false;
|
|
|
|
|
|
2018-12-21 05:03:12 +01:00
|
|
|
//get messages
|
2018-12-29 19:13:18 +01:00
|
|
|
if (isset($_SESSION['message']['display_last']['text']) && $_SESSION['message']['display_last']['text'] != '') {
|
|
|
|
|
$array = explode(' ',$_SESSION['message']['display_last']['text']);
|
|
|
|
|
if (is_array($array) && is_numeric($array[0]) && $array[0] > 0) {
|
|
|
|
|
if ($array[1] == 'messages') {
|
|
|
|
|
$limit = "limit ".$array[0]." offset 0 ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$since = "and message_date >= '".date("Y-m-d H:i:s", strtotime('-'.$_SESSION['message']['display_last']['text']))."' ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($limit == '' && $since == '') { $limit = "limit 25 offset 0"; } //default (message count)
|
2018-12-20 07:21:32 +01:00
|
|
|
$sql = "select * from v_messages ";
|
|
|
|
|
$sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
|
|
|
|
|
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
|
2018-12-29 19:13:18 +01:00
|
|
|
$sql .= $since;
|
2018-12-20 07:21:32 +01:00
|
|
|
$sql .= "and (message_from like '%".$number."' or message_to like '%".$number."') ";
|
2018-12-29 19:13:18 +01:00
|
|
|
$sql .= "order by message_date desc ";
|
|
|
|
|
$sql .= $limit;
|
2018-12-20 07:21:32 +01:00
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$messages = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
2018-12-29 19:13:18 +01:00
|
|
|
$messages = array_reverse($messages);
|
2018-12-20 07:21:32 +01:00
|
|
|
unset ($prep_statement, $sql);
|
|
|
|
|
|
2018-12-21 05:03:12 +01:00
|
|
|
//get media (if any)
|
2018-12-21 06:53:00 +01:00
|
|
|
$sql = "select message_uuid, message_media_uuid, message_media_type, length(message_media_content) as message_media_size from v_message_media ";
|
2018-12-21 05:03:12 +01:00
|
|
|
$sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
|
|
|
|
|
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
|
|
|
|
|
$sql .= "and message_uuid in ( ";
|
|
|
|
|
foreach ($messages as $message) {
|
|
|
|
|
$message_uuids[] = "'".$message['message_uuid']."'";
|
|
|
|
|
}
|
|
|
|
|
$sql .= implode(',', $message_uuids);
|
|
|
|
|
$sql .= ") ";
|
|
|
|
|
$sql .= "and message_media_type <> 'txt' ";
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$rows = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
unset ($prep_statement, $sql);
|
|
|
|
|
|
|
|
|
|
//prep media array
|
|
|
|
|
if (is_array($rows) && sizeof($rows) != 0) {
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
$message_media[$row['message_uuid']][$x]['uuid'] = $row['message_media_uuid'];
|
|
|
|
|
$message_media[$row['message_uuid']][$x]['type'] = $row['message_media_type'];
|
|
|
|
|
$message_media[$row['message_uuid']][$x]['size'] = $row['message_media_size'];
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 07:21:32 +01:00
|
|
|
//css styles
|
2018-12-21 02:42:10 +01:00
|
|
|
echo "<style>\n";
|
|
|
|
|
echo " .message-bubble {\n";
|
|
|
|
|
echo " display: block;\n";
|
|
|
|
|
echo " padding: 10px;\n";
|
|
|
|
|
echo " border: 1px solid;\n";
|
|
|
|
|
echo " margin-bottom: 10px;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
|
|
|
|
|
echo " .message-bubble-em {\n";
|
|
|
|
|
echo " margin-right: 10%;\n";
|
|
|
|
|
echo " border-radius: 0px 20px 20px 20px;\n";
|
|
|
|
|
echo " border-color: #cffec7;\n";
|
|
|
|
|
echo " background-color: #ecffe9;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
|
|
|
|
|
echo " .message-bubble-me {\n";
|
|
|
|
|
echo " margin-left: 10%;\n";
|
|
|
|
|
echo " border-radius: 20px 20px 0px 20px;\n";
|
|
|
|
|
echo " border-color: #cbf0ff;\n";
|
|
|
|
|
echo " background-color: #e5f7ff;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
|
|
|
|
|
echo " .message-bubble-when {\n";
|
|
|
|
|
echo " font-size: 65%;\n";
|
|
|
|
|
echo " line-height: 60%;\n";
|
|
|
|
|
echo " }\n";
|
2018-12-21 05:03:12 +01:00
|
|
|
|
|
|
|
|
echo " .message-media-link-em {\n";
|
|
|
|
|
echo " display: block;\n";
|
|
|
|
|
echo " position: inline;\n";
|
|
|
|
|
echo " margin: 5px 10px;\n";
|
|
|
|
|
echo " padding: 8px;\n";
|
|
|
|
|
echo " background: #cffec7;\n";
|
|
|
|
|
echo " border-radius: 7px;\n";
|
|
|
|
|
echo " text-align: center;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
|
|
|
|
|
echo " .message-media-link-me {\n";
|
|
|
|
|
echo " display: block;\n";
|
|
|
|
|
echo " position: inline;\n";
|
|
|
|
|
echo " margin: 5px 10px;\n";
|
|
|
|
|
echo " padding: 8px;\n";
|
|
|
|
|
echo " background: #cbf0ff;\n";
|
|
|
|
|
echo " border-radius: 7px;\n";
|
|
|
|
|
echo " text-align: center;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
|
2018-12-21 02:42:10 +01:00
|
|
|
echo "</style>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
|
|
|
|
|
if (!$refresh) {
|
2018-12-30 00:05:59 +01:00
|
|
|
echo "<div id='thread_messages' style='max-height: 300px; overflow: auto;'>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//output messages
|
|
|
|
|
if (is_array($messages) && sizeof($messages) != 0) {
|
|
|
|
|
foreach ($messages as $message) {
|
2018-12-21 05:03:12 +01:00
|
|
|
//parse from message
|
2018-12-20 07:21:32 +01:00
|
|
|
if ($message['message_direction'] == 'inbound') {
|
|
|
|
|
$message_from = $message['message_to'];
|
2018-12-21 05:03:12 +01:00
|
|
|
$media_source = format_phone($message['message_from']);
|
|
|
|
|
}
|
|
|
|
|
if ($message['message_direction'] == 'outbound') {
|
|
|
|
|
$media_source = format_phone($message['message_to']);
|
2018-12-20 07:21:32 +01:00
|
|
|
}
|
2018-12-21 05:03:12 +01:00
|
|
|
|
|
|
|
|
//message bubble
|
|
|
|
|
echo "<span class='message-bubble message-bubble-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
|
|
|
|
|
if ($message['message_text'] != '') {
|
2018-12-29 19:13:18 +01:00
|
|
|
echo str_replace("\n",'<br />',escape($message['message_text']))."<br />\n";
|
2018-12-21 05:03:12 +01:00
|
|
|
}
|
|
|
|
|
if (is_array($message_media[$message['message_uuid']]) && sizeof($message_media[$message['message_uuid']]) != 0) {
|
|
|
|
|
|
|
|
|
|
foreach ($message_media[$message['message_uuid']] as $media) {
|
|
|
|
|
if ($media['type'] != 'txt') {
|
2018-12-21 06:53:00 +01:00
|
|
|
if ($media['type'] == 'jpg' || $media['type'] == 'jpeg' || $media['type'] == 'gif' || $media['type'] == 'png') {
|
|
|
|
|
echo "<a href='#' onclick=\"display_media('".$media['uuid']."','".$media_source."');\" class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "<a href='message_media.php?id=".$media['uuid']."&src=".$media_source."&action=download' class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
|
|
|
|
|
}
|
2018-12-21 05:03:12 +01:00
|
|
|
echo "<img src='resources/images/attachment.png' style='width: 16px; height: 16px; border: none; margin-right: 10px;'>";
|
|
|
|
|
echo "<span style='font-size: 85%;'>".strtoupper($media['type']).' · '.strtoupper(byte_convert($media['size']))."</span>";
|
|
|
|
|
echo "</a>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-29 19:13:18 +01:00
|
|
|
echo " <span class='message-bubble-when'>".format_when_local($message['message_date'])."</span>\n";
|
2018-12-21 05:03:12 +01:00
|
|
|
echo "</span>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
}
|
2018-12-29 19:13:18 +01:00
|
|
|
echo "<span id='thread_bottom'></span>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-30 00:05:59 +01:00
|
|
|
//set current contact
|
|
|
|
|
echo "<script>$('#contact_current_number').val('".$number."');</script>\n";
|
|
|
|
|
|
2018-12-20 07:21:32 +01:00
|
|
|
if (!$refresh) {
|
|
|
|
|
echo "</div>\n";
|
|
|
|
|
|
|
|
|
|
if (permission_exists('message_add')) {
|
|
|
|
|
//output input form
|
2018-12-29 19:13:18 +01:00
|
|
|
echo "<form id='message_compose' method='post' enctype='multipart/form-data' action='message_send.php'>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
echo "<input type='hidden' name='message_from' value='".$message_from."'>\n";
|
|
|
|
|
echo "<input type='hidden' name='message_to' value='".$number."'>\n";
|
2018-12-29 19:13:18 +01:00
|
|
|
echo "<textarea class='formfld' id='message_text' name='message_text' style='width: 100%; max-width: 100%; min-height: 55px; border: 1px solid #cbcbcb; resize: vertical; padding: 5px 8px; margin-top: 10px; margin-bottom: 5px;' placeholder=\"".$text['description-enter_response']."\"></textarea>";
|
|
|
|
|
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='margin-top: 5px;'>\n";
|
|
|
|
|
echo " <tr>\n";
|
|
|
|
|
echo " <td><img src='resources/images/attachment.png' style='min-width: 20px; height: 20px; border: none; padding-right: 5px;'></td>\n";
|
|
|
|
|
echo " <td width='100%'><input type='file' class='formfld' multiple='multiple' name='message_media[]' id='message_new_media'></td>\n";
|
|
|
|
|
echo " </td>\n";
|
|
|
|
|
echo "</table>\n";
|
|
|
|
|
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='margin-top: 15px;'>\n";
|
|
|
|
|
echo " <tr>\n";
|
2018-12-30 00:05:59 +01:00
|
|
|
echo " <td align='left' width='50%'><input type='reset' class='btn' value='".$text['button-clear']."' onclick=\"$('#message_text').focus();\"></td>\n";
|
2018-12-29 19:13:18 +01:00
|
|
|
echo " <td align='center'><span id='thread_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; cursor: pointer;' onclick=\"refresh_thread_stop('".$number."');\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span></td>\n";
|
2018-12-30 00:05:59 +01:00
|
|
|
echo " <td align='right' width='50%'><input type='submit' class='btn' value='".$text['button-send']."' title=\"".$text['label-ctrl_enter']."\"></td>\n";
|
2018-12-29 19:13:18 +01:00
|
|
|
echo " </td>\n";
|
|
|
|
|
echo "</table>\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
echo "</form>\n";
|
|
|
|
|
|
|
|
|
|
//js to load messages for clicked number
|
|
|
|
|
echo "<script>\n";
|
|
|
|
|
//define form submit function
|
|
|
|
|
echo " $('#message_compose').submit(function(event) {\n";
|
|
|
|
|
echo " event.preventDefault();\n";
|
|
|
|
|
echo " $.ajax({\n";
|
2018-12-29 19:13:18 +01:00
|
|
|
echo " url: $(this).attr('action'),\n";
|
|
|
|
|
echo " type: $(this).attr('method'),\n";
|
|
|
|
|
echo " data: new FormData(this),\n";
|
|
|
|
|
echo " processData: false,\n";
|
|
|
|
|
echo " contentType: false,\n";
|
|
|
|
|
echo " cache: false,\n";
|
2018-12-20 07:21:32 +01:00
|
|
|
echo " success: function(){\n";
|
|
|
|
|
echo " document.getElementById('message_compose').reset();\n";
|
2018-12-27 17:12:24 +01:00
|
|
|
if (!http_user_agent('mobile')) {
|
|
|
|
|
echo " if ($('#message_new_layer').is(':hidden')) {\n";
|
|
|
|
|
echo " $('#message_text').focus();\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
}
|
2018-12-20 07:21:32 +01:00
|
|
|
echo " refresh_thread('".$number."','true');\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo " });\n";
|
|
|
|
|
echo " });\n";
|
|
|
|
|
//enable ctrl+enter to send
|
|
|
|
|
echo " $('#message_text').keydown(function (event) {\n";
|
|
|
|
|
echo " if ((event.keyCode == 10 || event.keyCode == 13) && event.ctrlKey) {\n";
|
|
|
|
|
echo " $('#message_compose').submit();\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo " });\n";
|
|
|
|
|
|
|
|
|
|
echo "</script>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|