diff --git a/app/messages/app_config.php b/app/messages/app_config.php
index 60fee28be2..7b48744f74 100644
--- a/app/messages/app_config.php
+++ b/app/messages/app_config.php
@@ -31,8 +31,24 @@
$apps[$x]['permissions'][$y]['name'] = 'message_all';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
+ $apps[$x]['permissions'][$y]['name'] = 'message_media_view';
+ $apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
+ //$apps[$x]['permissions'][$y]['groups'][] = 'admin';
+ $y++;
+ $apps[$x]['permissions'][$y]['name'] = 'message_media_add';
+ $apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
+ //$apps[$x]['permissions'][$y]['groups'][] = 'admin';
+ $y++;
+ $apps[$x]['permissions'][$y]['name'] = 'message_media_edit';
+ $apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
+ //$apps[$x]['permissions'][$y]['groups'][] = 'admin';
+ $y++;
+ $apps[$x]['permissions'][$y]['name'] = 'message_media_delete';
+ $apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
+ //$apps[$x]['permissions'][$y]['groups'][] = 'admin';
+ $y++;
- //Messages
+ //messages table
$y = 0;
$apps[$x]['db'][$y]['table']['name'] = 'v_messages';
$apps[$x]['db'][$y]['table']['parent'] = '';
@@ -68,45 +84,101 @@
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'contact_uuid';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_type';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message type.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_direction';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message direction.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_date';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'timestamp';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'date';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'timestamp';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message date.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_from';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message from.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_to';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message to.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_text';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message text.';
$z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_json';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = '';
+
+ //message media table
+ $y++;
+ $apps[$x]['db'][$y]['table']['name'] = 'v_message_media';
+ $apps[$x]['db'][$y]['table']['parent'] = 'v_messages';
+ $z = 0;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_media_uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_messages';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'message_uuid';
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = 'user_uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_users';
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'user_uuid';
+ $z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_media_type';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message media type.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_media_url';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message media url.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_media_content';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the message media content.';
$z++;
- $apps[$x]['db'][$y]['fields'][$z]['name'] = 'message_json';
- $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
- $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = '';
- $z++;
+
//default settings
$y=0;
diff --git a/app/messages/app_languages.php b/app/messages/app_languages.php
index b54a1f6ca9..9918b92c41 100644
--- a/app/messages/app_languages.php
+++ b/app/messages/app_languages.php
@@ -141,7 +141,7 @@
$text['description-message_type']['sv-se'] = '';
$text['description-message_type']['uk-ua'] = '';
- $text['label-sms']['en-us'] = 'sms';
+ $text['label-sms']['en-us'] = 'SMS';
$text['label-sms']['ar-eg'] = '';
$text['label-sms']['de-at'] = '';
$text['label-sms']['de-ch'] = '';
@@ -160,7 +160,7 @@
$text['label-sms']['sv-se'] = '';
$text['label-sms']['uk-ua'] = '';
- $text['label-mms']['en-us'] = 'mms';
+ $text['label-mms']['en-us'] = 'MMS';
$text['label-mms']['ar-eg'] = '';
$text['label-mms']['de-at'] = '';
$text['label-mms']['de-ch'] = '';
@@ -179,7 +179,26 @@
$text['label-mms']['sv-se'] = '';
$text['label-mms']['uk-ua'] = '';
- $text['label-sip']['en-us'] = 'sip';
+ $text['label-sms']['en-us'] = 'SMS';
+ $text['label-sms']['ar-eg'] = '';
+ $text['label-sms']['de-at'] = '';
+ $text['label-sms']['de-ch'] = '';
+ $text['label-sms']['de-de'] = '';
+ $text['label-sms']['es-mx'] = '';
+ $text['label-sms']['fr-ca'] = '';
+ $text['label-sms']['fr-fr'] = '';
+ $text['label-sms']['he-il'] = '';
+ $text['label-sms']['it-it'] = '';
+ $text['label-sms']['nl-nl'] = '';
+ $text['label-sms']['pl-pl'] = '';
+ $text['label-sms']['pt-br'] = '';
+ $text['label-sms']['pt-pt'] = '';
+ $text['label-sms']['ro-ro'] = '';
+ $text['label-sms']['ru-ru'] = '';
+ $text['label-sms']['sv-se'] = '';
+ $text['label-sms']['uk-ua'] = '';
+
+ $text['label-sip']['en-us'] = 'SIP';
$text['label-sip']['ar-eg'] = '';
$text['label-sip']['de-at'] = '';
$text['label-sip']['de-ch'] = '';
@@ -198,7 +217,26 @@
$text['label-sip']['sv-se'] = '';
$text['label-sip']['uk-ua'] = '';
- $text['label-message']['en-us'] = 'message';
+ $text['label-chat']['en-us'] = 'Chat';
+ $text['label-chat']['ar-eg'] = '';
+ $text['label-chat']['de-at'] = '';
+ $text['label-chat']['de-ch'] = '';
+ $text['label-chat']['de-de'] = '';
+ $text['label-chat']['es-mx'] = '';
+ $text['label-chat']['fr-ca'] = '';
+ $text['label-chat']['fr-fr'] = '';
+ $text['label-chat']['he-il'] = '';
+ $text['label-chat']['it-it'] = '';
+ $text['label-chat']['nl-nl'] = '';
+ $text['label-chat']['pl-pl'] = '';
+ $text['label-chat']['pt-br'] = '';
+ $text['label-chat']['pt-pt'] = '';
+ $text['label-chat']['ro-ro'] = '';
+ $text['label-chat']['ru-ru'] = '';
+ $text['label-chat']['sv-se'] = '';
+ $text['label-chat']['uk-ua'] = '';
+
+ $text['label-message']['en-us'] = 'Message';
$text['label-message']['ar-eg'] = '';
$text['label-message']['de-at'] = '';
$text['label-message']['de-ch'] = '';
@@ -257,43 +295,81 @@
$text['description-message_direction']['sv-se'] = '';
$text['description-message_direction']['uk-ua'] = '';
- $text['label-send']['en-us'] = 'send';
- $text['label-send']['ar-eg'] = '';
- $text['label-send']['de-at'] = '';
- $text['label-send']['de-ch'] = '';
- $text['label-send']['de-de'] = '';
- $text['label-send']['es-mx'] = '';
- $text['label-send']['fr-ca'] = '';
- $text['label-send']['fr-fr'] = '';
- $text['label-send']['he-il'] = '';
- $text['label-send']['it-it'] = '';
- $text['label-send']['nl-nl'] = '';
- $text['label-send']['pl-pl'] = '';
- $text['label-send']['pt-br'] = '';
- $text['label-send']['pt-pt'] = '';
- $text['label-send']['ro-ro'] = '';
- $text['label-send']['ru-ru'] = '';
- $text['label-send']['sv-se'] = '';
- $text['label-send']['uk-ua'] = '';
+ $text['label-outbound']['en-us'] = 'Outbound';
+ $text['label-outbound']['ar-eg'] = '';
+ $text['label-outbound']['de-at'] = '';
+ $text['label-outbound']['de-ch'] = '';
+ $text['label-outbound']['de-de'] = '';
+ $text['label-outbound']['es-mx'] = '';
+ $text['label-outbound']['fr-ca'] = '';
+ $text['label-outbound']['fr-fr'] = '';
+ $text['label-outbound']['he-il'] = '';
+ $text['label-outbound']['it-it'] = '';
+ $text['label-outbound']['nl-nl'] = '';
+ $text['label-outbound']['pl-pl'] = '';
+ $text['label-outbound']['pt-br'] = '';
+ $text['label-outbound']['pt-pt'] = '';
+ $text['label-outbound']['ro-ro'] = '';
+ $text['label-outbound']['ru-ru'] = '';
+ $text['label-outbound']['sv-se'] = '';
+ $text['label-outbound']['uk-ua'] = '';
- $text['label-receive']['en-us'] = 'receive';
- $text['label-receive']['ar-eg'] = '';
- $text['label-receive']['de-at'] = '';
- $text['label-receive']['de-ch'] = '';
- $text['label-receive']['de-de'] = '';
- $text['label-receive']['es-mx'] = '';
- $text['label-receive']['fr-ca'] = '';
- $text['label-receive']['fr-fr'] = '';
- $text['label-receive']['he-il'] = '';
- $text['label-receive']['it-it'] = '';
- $text['label-receive']['nl-nl'] = '';
- $text['label-receive']['pl-pl'] = '';
- $text['label-receive']['pt-br'] = '';
- $text['label-receive']['pt-pt'] = '';
- $text['label-receive']['ro-ro'] = '';
- $text['label-receive']['ru-ru'] = '';
- $text['label-receive']['sv-se'] = '';
- $text['label-receive']['uk-ua'] = '';
+ $text['label-inbound']['en-us'] = 'Inbound';
+ $text['label-inbound']['ar-eg'] = '';
+ $text['label-inbound']['de-at'] = '';
+ $text['label-inbound']['de-ch'] = '';
+ $text['label-inbound']['de-de'] = '';
+ $text['label-inbound']['es-mx'] = '';
+ $text['label-inbound']['fr-ca'] = '';
+ $text['label-inbound']['fr-fr'] = '';
+ $text['label-inbound']['he-il'] = '';
+ $text['label-inbound']['it-it'] = '';
+ $text['label-inbound']['nl-nl'] = '';
+ $text['label-inbound']['pl-pl'] = '';
+ $text['label-inbound']['pt-br'] = '';
+ $text['label-inbound']['pt-pt'] = '';
+ $text['label-inbound']['ro-ro'] = '';
+ $text['label-inbound']['ru-ru'] = '';
+ $text['label-inbound']['sv-se'] = '';
+ $text['label-inbound']['uk-ua'] = '';
+
+ $text['button-new-message']['en-us'] = 'New Message';
+ $text['button-new-message']['ar-eg'] = '';
+ $text['button-new-message']['de-at'] = '';
+ $text['button-new-message']['de-ch'] = '';
+ $text['button-new-message']['de-de'] = '';
+ $text['button-new-message']['es-mx'] = '';
+ $text['button-new-message']['fr-ca'] = '';
+ $text['button-new-message']['fr-fr'] = '';
+ $text['button-new-message']['he-il'] = '';
+ $text['button-new-message']['it-it'] = '';
+ $text['button-new-message']['nl-nl'] = '';
+ $text['button-new-message']['pl-pl'] = '';
+ $text['button-new-message']['pt-br'] = '';
+ $text['button-new-message']['pt-pt'] = '';
+ $text['button-new-message']['ro-ro'] = '';
+ $text['button-new-message']['ru-ru'] = '';
+ $text['button-new-message']['sv-se'] = '';
+ $text['button-new-message']['uk-ua'] = '';
+
+ $text['button-log']['en-us'] = 'Log';
+ $text['button-log']['ar-eg'] = '';
+ $text['button-log']['de-at'] = '';
+ $text['button-log']['de-ch'] = '';
+ $text['button-log']['de-de'] = '';
+ $text['button-log']['es-mx'] = '';
+ $text['button-log']['fr-ca'] = '';
+ $text['button-log']['fr-fr'] = '';
+ $text['button-log']['he-il'] = '';
+ $text['button-log']['it-it'] = '';
+ $text['button-log']['nl-nl'] = '';
+ $text['button-log']['pl-pl'] = '';
+ $text['button-log']['pt-br'] = '';
+ $text['button-log']['pt-pt'] = '';
+ $text['button-log']['ro-ro'] = '';
+ $text['button-log']['ru-ru'] = '';
+ $text['button-log']['sv-se'] = '';
+ $text['button-log']['uk-ua'] = '';
$text['label-message_date']['en-us'] = 'Date';
$text['label-message_date']['ar-eg'] = '';
@@ -435,6 +511,26 @@
$text['label-message_text']['sv-se'] = '';
$text['label-message_text']['uk-ua'] = '';
+ $text['label-message_media']['en-us'] = 'Media';
+ $text['label-message_media']['ar-eg'] = '';
+ $text['label-message_media']['de-at'] = '';
+ $text['label-message_media']['de-ch'] = '';
+ $text['label-message_media']['de-de'] = '';
+ $text['label-message_media']['es-cl'] = '';
+ $text['label-message_media']['es-mx'] = '';
+ $text['label-message_media']['fr-ca'] = '';
+ $text['label-message_media']['fr-fr'] = '';
+ $text['label-message_media']['he-il'] = '';
+ $text['label-message_media']['it-it'] = '';
+ $text['label-message_media']['nl-nl'] = '';
+ $text['label-message_media']['pl-pl'] = '';
+ $text['label-message_media']['pt-br'] = '';
+ $text['label-message_media']['pt-pt'] = '';
+ $text['label-message_media']['ro-ro'] = '';
+ $text['label-message_media']['ru-ru'] = '';
+ $text['label-message_media']['sv-se'] = '';
+ $text['label-message_media']['uk-ua'] = '';
+
$text['description-message_text']['en-us'] = 'Enter the message text.';
$text['description-message_text']['ar-eg'] = '';
$text['description-message_text']['de-at'] = '';
diff --git a/app/messages/index.php b/app/messages/index.php
index d6afae6dbf..abf8768396 100644
--- a/app/messages/index.php
+++ b/app/messages/index.php
@@ -28,6 +28,9 @@
require_once "root.php";
require_once "resources/require.php";
+//default authorized to false
+ $authorized = 'false';
+
//get the user settings
$sql = "select user_uuid, domain_uuid from v_user_settings ";
$sql .= "where user_setting_category = 'message' ";
@@ -39,16 +42,11 @@
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_NAMED);
- }
-
-//default authorized to false
- $authorized = 'false';
-
-//get the user
- if (isset($row['user_uuid']) && strlen($row['user_uuid']) > 0) {
- $domain_uuid = $row['domain_uuid'];
- $user_uuid = $row['user_uuid'];
- $authorized = 'true';
+ if (is_uuid($row['user_uuid'])) {
+ $domain_uuid = $row['domain_uuid'];
+ $user_uuid = $row['user_uuid'];
+ $authorized = 'true';
+ }
}
//authorization failed
@@ -70,23 +68,19 @@
exit();
}
-//get the data
+//get the raw input data
$json = file_get_contents('php://input');
-//decode the json
+//decode the json into array
$message = json_decode($json, true);
-//get a unique id
- $message_uuid = uuid();
-
//get the source phone number
- $phone_number = $message["from"];
- $phone_number = preg_replace('{[\D]}', '', $phone_number);
+ $phone_number = preg_replace('{[\D]}', '', $message['from']);
//get the contact uuid
- $sql = "SELECT c.contact_uuid ";
- $sql .= "FROM v_contacts as c, v_contact_phones as p ";
- $sql .= "WHERE p.contact_uuid = c.contact_uuid ";
+ $sql = "select c.contact_uuid ";
+ $sql .= "from v_contacts as c, v_contact_phones as p ";
+ $sql .= "where p.contact_uuid = c.contact_uuid ";
//$sql .= "and p.phone_number = :phone_number ";
$sql .= "and p.phone_number = '".$phone_number."' ";
$sql .= "and c.domain_uuid = '".$domain_uuid."' ";
@@ -99,39 +93,44 @@
//$contact_name_family = $row['contact_name_family'];
//$contact_organization = $row['contact_organization'];
-//build the array
- $array['messages'][0]["domain_uuid"] = $domain_uuid;
- $array['messages'][0]["user_uuid"] = $user_uuid;
- $array['messages'][0]["contact_uuid"] = $contact_uuid;
- $array['messages'][0]['message_uuid'] = $message_uuid;
- $array['messages'][0]['message_json'] = $json;
- $array['messages'][0]['message_direction'] = 'receive';
- $array['messages'][0]['message_date'] = 'now()';
- $array['messages'][0]['message_type'] = 'sms';
- $array['messages'][0]['message_from'] = $message["from"];
- $array['messages'][0]['message_to'] = $message["to"];
- $array['messages'][0]['message_text'] = $message["text"];
-//get the media
- if (is_array($message["media"])) {
- foreach($message["media"] as $media) {
- $media_extension = pathinfo($media, PATHINFO_EXTENSION);
- if ($media_extension !== "xml") {
- $array['messages'][0]['message_media_type'] = $media_extension;
- $array['messages'][0]['message_media_url'] = $media;
- $array['messages'][0]['message_media_content'] = base64_encode(file_get_contents($media));
+//build message array
+ $message_uuid = uuid();
+ $array['messages'][0]['message_uuid'] = $message_uuid;
+ $array['messages'][0]['domain_uuid'] = $domain_uuid;
+ $array['messages'][0]['user_uuid'] = $user_uuid;
+ $array['messages'][0]['contact_uuid'] = $contact_uuid;
+ $array['messages'][0]['message_uuid'] = $message_uuid;
+ $array['messages'][0]['message_type'] = is_array($message['media']) ? 'mms' : 'sms';
+ $array['messages'][0]['message_direction'] = 'inbound';
+ $array['messages'][0]['message_date'] = 'now()';
+ $array['messages'][0]['message_from'] = $message['from'];
+ $array['messages'][0]['message_to'] = $message['to'];
+ $array['messages'][0]['message_text'] = $message['text'];
+ $array['messages'][0]['message_json'] = $json;
+
+//build message media array (if necessary)
+ if (is_array($message['media'])) {
+ foreach($message['media'] as $index => $media_url) {
+ $media_type = pathinfo($media_url, PATHINFO_EXTENSION);
+ if ($media_type !== 'xml') {
+ $array['message_media'][$index]['message_media_uuid'] = uuid();
+ $array['message_media'][$index]['message_uuid'] = $message_uuid;
+ $array['message_media'][$index]['domain_uuid'] = $domain_uuid;
+ $array['message_media'][$index]['user_uuid'] = $user_uuid;
+ $array['message_media'][$index]['message_media_type'] = $media_type;
+ $array['message_media'][$index]['message_media_url'] = $media_url;
+ $array['message_media'][$index]['message_media_content'] = base64_encode(file_get_contents($media_url));
}
}
}
-//convert the array to json
- $array_json = json_encode($array);
-
-//add the dialplan permission
+//add the required permission
$p = new permissions;
$p->add("message_add", "temp");
+ $p->add("message_media_add", "temp");
-//save to the data
+//save message to the database
$database = new database;
$database->app_name = 'messages';
$database->app_uuid = '4a20815d-042c-47c8-85df-085333e79b87';
@@ -141,6 +140,10 @@
//remove the temporary permission
$p->delete("message_add", "temp");
+ $p->delete("message_media_add", "temp");
+
+//convert the array to json
+ $array_json = json_encode($array);
//get the list of extensions using the user_uuid
$sql = "select * from v_domains as d, v_extensions as e ";
diff --git a/app/messages/message_delete.php b/app/messages/message_delete.php
index 1e1159776f..c92efc11bd 100644
--- a/app/messages/message_delete.php
+++ b/app/messages/message_delete.php
@@ -50,7 +50,7 @@
unset($sql);
//redirect the user
- header('Location: messages.php');
+ header('Location: messages_log.php');
}
diff --git a/app/messages/message_edit.php b/app/messages/message_edit.php
index fd905b309e..20ff959360 100644
--- a/app/messages/message_edit.php
+++ b/app/messages/message_edit.php
@@ -195,7 +195,7 @@
echo "
\n";
echo "".$text['title-message']."
| \n";
echo "\n";
- echo " ";
+ echo " ";
echo " ";
echo " | \n";
echo "
\n";
@@ -206,10 +206,8 @@
echo "\n";
echo "\n";
echo " \n";
echo " \n";
@@ -223,25 +221,9 @@
echo " | \n";
echo "\n";
echo " \n";
echo " \n";
echo $text['description-message_type']."\n";
@@ -253,21 +235,10 @@
echo " ".$text['label-message_direction']."\n";
echo " | \n";
echo "\n";
- echo " \n";
+ echo " \n";
echo " \n";
echo $text['description-message_direction']."\n";
echo " | \n";
@@ -316,7 +287,7 @@
echo $text['description-message_text']."\n";
echo "\n";
echo "\n";
-
+
if (strlen($message_media_type) > 0) {
echo "\n";
echo "\n";
diff --git a/app/messages/message_send.php b/app/messages/message_send.php
index 894f4806fa..c8d4546fa6 100644
--- a/app/messages/message_send.php
+++ b/app/messages/message_send.php
@@ -43,14 +43,7 @@
$text = $language->get();
//action add or update
- if (isset($_REQUEST["id"])) {
- $action = "update";
- $message_uuid = check_str($_REQUEST["id"]);
- $id = check_str($_REQUEST["id"]);
- }
- else {
- $action = "add";
- }
+ $action = "add";
//define the http request
function http_request($url, $method, $headers = null, $content) {
@@ -70,51 +63,27 @@
//get http post variables and set them to php variables
if (is_array($_POST)) {
- //$message_uuid = check_str($_POST["message_uuid"]);
- //$user_uuid = check_str($_POST["user_uuid"]);
$message_type = check_str($_POST["message_type"]);
- //$message_date = check_str($_POST["message_date"]);
$message_from = check_str($_POST["message_from"]);
$message_to = check_str($_POST["message_to"]);
$message_text = check_str($_POST["message_text"]);
- //$message_media_type = check_str($_POST["message_media_type"]);
- //$message_media_url = check_str($_POST["message_media_url"]);
- //$message_media_content = check_str($_POST["message_media_content"]);
- //$message_json = check_str($_POST["message_json"]);
}
//process the user data and save it to the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
- //check for all required data
- $msg = '';
- //if (strlen($user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-user_uuid']." \n"; }
- if (strlen($message_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_type']." \n"; }
- //if (strlen($message_direction) == 0) { $msg .= $text['message-required']." ".$text['label-message_direction']." \n"; }
- //if (strlen($message_date) == 0) { $msg .= $text['message-required']." ".$text['label-message_date']." \n"; }
- if (strlen($message_from) == 0) { $msg .= $text['message-required']." ".$text['label-message_from']." \n"; }
- if (strlen($message_to) == 0) { $msg .= $text['message-required']." ".$text['label-message_to']." \n"; }
- //if (strlen($message_text) == 0) { $msg .= $text['message-required']." ".$text['label-message_text']." \n"; }
- //if (strlen($message_media_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_type']." \n"; }
- //if (strlen($message_media_url) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_url']." \n"; }
- //if (strlen($message_media_content) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_content']." \n"; }
- //if (strlen($message_json) == 0) { $msg .= $text['message-required']." ".$text['label-message_json']." \n"; }
- if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
- require_once "resources/header.php";
- require_once "resources/persist_form_var.php";
- echo "\n";
- echo " \n";
- echo $msg." ";
- echo " |
\n";
- persistformvar($_POST);
- echo " \n";
- require_once "resources/footer.php";
- return;
- }
-
//get the source phone number
$phone_number = preg_replace('{[\D]}', '', $message_to);
+ //error check
+ if (
+ ($message_type != 'sms' && $message_type != 'mms' && $message_type != 'chat') ||
+ !is_numeric($message_from) ||
+ !is_numeric($message_to) ||
+ $message_text == '') {
+ exit;
+ }
+
//get the contact uuid
//$sql = "SELECT trim(c.contact_name_given || ' ' || c.contact_name_family || ' (' || c.contact_organization || ')') AS name, p.phone_number AS number ";
$sql = "SELECT c.contact_uuid ";
@@ -138,7 +107,7 @@
$message['user_uuid'] = $_SESSION["user_uuid"];
$message['contact_uuid'] = $contact_uuid;
$message['message_type'] = $message_type;
- $message['message_direction'] = 'send';
+ $message['message_direction'] = 'outbound';
$message['message_date'] = 'now()';
$message['message_from'] = $message_from;
$message['message_to'] = $message_to;
@@ -192,101 +161,7 @@
//redirect the user
//$_SESSION["message"] = $text['message-sent'];
- header('Location: messages.php');
- return;
+ return true;
} //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0)
-//show the header
- require_once "resources/header.php";
-
-//show the content
- echo "";
- echo "
";
-
-//include the footer
- require_once "resources/footer.php";
-
?>
diff --git a/app/messages/messages.php b/app/messages/messages.php
index 78285d7b5d..889edd7d03 100644
--- a/app/messages/messages.php
+++ b/app/messages/messages.php
@@ -30,10 +30,7 @@
require_once "resources/check_auth.php";
//check permissions
- if (permission_exists('message_view')) {
- //access granted
- }
- else {
+ if (!permission_exists('message_view')) {
echo "access denied";
exit;
}
@@ -42,136 +39,118 @@
$language = new text;
$text = $language->get();
-//get the action
- if (is_array($_POST["messages"])) {
- $messages = $_POST["messages"];
- foreach($messages as $row) {
- if ($row['action'] == 'delete') {
- $action = 'delete';
- break;
- }
+//get (from) destinations
+ $sql = "select destination_number from v_destinations ";
+ $sql .= "where domain_uuid = '".$domain_uuid."' ";
+ $sql .= "and destination_enabled = 'true' ";
+ $sql .= "order by destination_number asc ";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $rows = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ //view_array($rows);
+ if (is_array($rows) && sizeof($rows)) {
+ foreach ($rows as $row) {
+ $destinations[] = $row['destination_number'];
}
}
-
-//delete the messages
- if (permission_exists('message_delete')) {
- if ($action == "delete") {
- //download
- $obj = new messages;
- $obj->delete($messages);
- //delete message
- message::add($text['message-delete']);
- }
- }
-
-//get variables used to control the order
- $order_by = check_str($_GET["order_by"]);
- $order = check_str($_GET["order"]);
-
-//add the search term
- $search = strtolower(check_str($_GET["search"]));
- if (strlen($search) > 0) {
- $sql_search = " (";
- $sql_search .= "lower(message_type) like '%".$search."%' ";
- $sql_search .= "or lower(message_direction) like '%".$search."%' ";
- $sql_search .= "or lower(message_date) like '%".$search."%' ";
- $sql_search .= "or lower(message_from) like '%".$search."%' ";
- $sql_search .= "or lower(message_to) like '%".$search."%' ";
- $sql_search .= "or lower(message_text) like '%".$search."%' ";
- $sql_search .= "or lower(message_media_type) like '%".$search."%' ";
- $sql_search .= ") ";
- }
+ unset ($prep_statement, $sql, $row, $record);
//additional includes
require_once "resources/header.php";
- require_once "resources/paging.php";
-//prepare to page the results
- $sql = "select count(message_uuid) as num_rows from v_messages ";
- if ($_GET['show'] == "all" && permission_exists('message_all')) {
- if (isset($sql_search)) {
- $sql .= "where ".$sql_search;
- }
- } else {
- $sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
- $sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
- if (isset($sql_search)) {
- $sql .= "and ".$sql_search;
- }
- }
- $prep_statement = $db->prepare($sql);
- if ($prep_statement) {
- $prep_statement->execute();
- $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
- if ($row['num_rows'] > 0) {
- $num_rows = $row['num_rows'];
- }
- else {
- $num_rows = '0';
- }
- }
+//styles
+ echo "\n";
+
+//new message layer
+ echo "\n";
+ echo " \n";
+ echo " \n";
//show the content
echo "\n";
- echo " |