Messages app modifications.

This commit is contained in:
reliberate
2018-12-19 22:21:32 -08:00
parent 8439adbfa2
commit 4e795e642e
12 changed files with 1066 additions and 465 deletions

View File

@@ -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;

View File

@@ -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'] = '';

View File

@@ -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 ";

View File

@@ -50,7 +50,7 @@
unset($sql);
//redirect the user
header('Location: messages.php');
header('Location: messages_log.php');
}

View File

@@ -195,7 +195,7 @@
echo "<tr>\n";
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-message']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='messages.php'\" value='".$text['button-back']."'>";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='messages_log.php'\" value='".$text['button-back']."'>";
echo " <input type='submit' class='btn' value='".$text['button-save']."'>";
echo "</td>\n";
echo "</tr>\n";
@@ -206,10 +206,8 @@
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='user_uuid'>\n";
echo " <option value=''></option>\n";
foreach($users as $row) {
if ($row['user_uuid'] == $user_uuid) { $selected = "selected='selected'"; } else { $selected = ''; }
echo " <option value='".escape($row['user_uuid'])."' $selected>".escape($row['username'])."</option>\n";
echo " <option value='".escape($row['user_uuid'])."' ".($row['user_uuid'] == $user_uuid ? "selected='selected'" : null).">".escape($row['username'])."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
@@ -223,25 +221,9 @@
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='message_type'>\n";
echo " <option value=''></option>\n";
if ($message_type == "sms") {
echo " <option value='sms' selected='selected'>".$text['label-sms']."</option>\n";
}
else {
echo " <option value='sms'>".$text['label-sms']."</option>\n";
}
if ($message_type == "mms") {
echo " <option value='mms' selected='selected'>".$text['label-mms']."</option>\n";
}
else {
echo " <option value='mms'>".$text['label-mms']."</option>\n";
}
if ($message_type == "chat") {
echo " <option value='chat' selected='selected'>".$text['label-chat']."</option>\n";
}
else {
echo " <option value='chat'>".$text['label-chat']."</option>\n";
}
echo " <option value='sms' ".($message_type == 'sms' ? "selected='selected'" : null).">".$text['label-sms']."</option>\n";
echo " <option value='mms' ".($message_type == 'mms' ? "selected='selected'" : null).">".$text['label-mms']."</option>\n";
echo " <option value='chat' ".($message_type == 'chat' ? "selected='selected'" : null).">".$text['label-chat']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-message_type']."\n";
@@ -253,21 +235,10 @@
echo " ".$text['label-message_direction']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='message_direction'>\n";
echo " <option value=''></option>\n";
if ($message_direction == "receive") {
echo " <option value='inbound' selected='selected'>".$text['label-receive']."</option>\n";
}
else {
echo " <option value='inbound'>".$text['label-receive']."</option>\n";
}
if ($message_direction == "send") {
echo " <option value='outbound' selected='selected'>".$text['label-send']."</option>\n";
}
else {
echo " <option value='outbound'>".$text['label-send']."</option>\n";
}
echo " </select>\n";
echo " <select class='formfld' name='message_direction'>\n";
echo " <option value='inbound' ".($message_direction == 'inbound' ? "selected='selected'" : null).">".$text['label-inbound']."</option>\n";
echo " <option value='outbound' ".($message_direction == 'outbound' ? "selected='selected'" : null).">".$text['label-outbound']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-message_direction']."\n";
echo "</td>\n";
@@ -316,7 +287,7 @@
echo $text['description-message_text']."\n";
echo "</td>\n";
echo "</tr>\n";
if (strlen($message_media_type) > 0) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";

View File

@@ -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']."<br>\n"; }
if (strlen($message_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_type']."<br>\n"; }
//if (strlen($message_direction) == 0) { $msg .= $text['message-required']." ".$text['label-message_direction']."<br>\n"; }
//if (strlen($message_date) == 0) { $msg .= $text['message-required']." ".$text['label-message_date']."<br>\n"; }
if (strlen($message_from) == 0) { $msg .= $text['message-required']." ".$text['label-message_from']."<br>\n"; }
if (strlen($message_to) == 0) { $msg .= $text['message-required']." ".$text['label-message_to']."<br>\n"; }
//if (strlen($message_text) == 0) { $msg .= $text['message-required']." ".$text['label-message_text']."<br>\n"; }
//if (strlen($message_media_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_type']."<br>\n"; }
//if (strlen($message_media_url) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_url']."<br>\n"; }
//if (strlen($message_media_content) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_content']."<br>\n"; }
//if (strlen($message_json) == 0) { $msg .= $text['message-required']." ".$text['label-message_json']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\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 "<form name='frm' id='frm' method='post' action=''>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-message']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='messages.php'\" value='".$text['button-back']."'>";
//echo " <input type='submit' class='btn' value='".$text['button-send']."'>";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_type']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='message_type'>\n";
echo " <option value=''></option>\n";
if ($message_type == "sms") {
echo " <option value='sms' selected='selected'>".$text['label-sms']."</option>\n";
}
else {
echo " <option value='sms'>".$text['label-sms']."</option>\n";
}
if ($message_type == "mms") {
echo " <option value='mms' selected='selected'>".$text['label-mms']."</option>\n";
}
else {
echo " <option value='mms'>".$text['label-mms']."</option>\n";
}
if ($message_type == "chat") {
echo " <option value='chat' selected='selected'>".$text['label-chat']."</option>\n";
}
else {
echo " <option value='chat'>".$text['label-chat']."</option>\n";
}
echo " </select>\n";
echo "<br />\n";
echo $text['description-message_type']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_from']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_from' maxlength='255' value=\"".escape($message_from)."\">\n";
echo "<br />\n";
echo $text['description-message_from']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_to']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <input class='formfld' type='text' name='message_to' maxlength='255' value=\"".escape($message_to)."\">\n";
echo "<br />\n";
echo $text['description-message_to']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-message_text']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
//echo " <input class='formfld' type='text' name='message_text' maxlength='255' value=\"".escape($message_text)."\">\n";
echo " <textarea class='formfld' style='width: 100%; height: 80px;' name='message_text'></textarea>\n";
echo "<br />\n";
echo $text['description-message_text']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='message_uuid' value='".escape($message_uuid)."'>\n";
echo " <input type='submit' class='btn' value='".$text['button-send']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "</form>";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>

View File

@@ -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 "<style>\n";
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".$search;
if ($_GET['show'] == "all" && permission_exists('message_all')) {
$param .= "&show=all";
}
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
//get the list
$sql = "select * 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;
}
}
$sql .= "order by message_date desc ";
$sql .= "limit $rows_per_page offset $offset ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$messages = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//define the checkbox_toggle function
echo "<script type=\"text/javascript\">\n";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('checkbox_all').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " #message_new_layer {\n";
echo " z-index: 999999;\n";
echo " position: absolute;\n";
echo " left: 0px;\n";
echo " top: 0px;\n";
echo " right: 0px;\n";
echo " bottom: 0px;\n";
echo " text-align: center;\n";
echo " vertical-align: middle;\n";
echo " }\n";
echo "</script>\n";
echo " #message_new_container {\n";
echo " display: block;\n";
echo " background-color: #fff;\n";
echo " padding: 20px 30px;\n";
echo " margin: auto 30%;\n";
echo " text-align: left;\n";
echo " -webkit-box-shadow: 0px 1px 20px #888;\n";
echo " -moz-box-shadow: 0px 1px 20px #888;\n";
echo " box-shadow: 0px 1px 20px #888;\n";
echo " }\n";
echo "</style>\n";
//new message layer
echo "<div id='message_new_layer' style='display: none;'>\n";
echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
echo " <tr>\n";
echo " <td align='center' valign='middle'>\n";
echo " <form id='message_new'>\n";
echo " <input type='hidden' name='message_type' value='sms'>\n";
echo " <span id='message_new_container'>\n";
echo " <b>New Message</b><br /><br />\n";
echo " <table width='100%'>\n";
echo " <tr>\n";
echo " <td class='vncell'>From</td>\n";
echo " <td class='vtable'>\n";
if (is_array($destinations) && sizeof($destinations) != 0) {
echo " <select class='formfld' name='message_from' id='message_new_from'>\n";
foreach ($destinations as $destination) {
echo " <option value='".$destination."'>".format_phone($destination)."</option>\n";
}
echo " </select>\n";
}
else {
echo " <input type='text' class='formfld' name='message_from' id='message_new_from'>\n";
}
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class='vncell'>To</td>\n";
echo " <td class='vtable'>\n";
echo " <input type='text' class='formfld' name='message_to' id='message_new_to'>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class='vncell'>Message</td>\n";
echo " <td class='vtable'>\n";
echo " <textarea class='formfld' style='width: 100%; height: 80px;' name='message_text' name='message_new_text'></textarea>\n";
echo " </td>\n";
echo " </tr>\n";
/*
echo " <tr>\n";
echo " <td class='vncell'>Media</td>\n";
echo " <td class='vtable'>\n";
echo " <input type='file' class='formfld' name='message_media' id='message_new_media'>\n";
echo " </td>\n";
echo " </tr>\n";
*/
echo " </table>\n";
echo " <center>\n";
echo " <input type='reset' class='btn' style='float: left; margin-top: 15px;' value='CLEAR' onclick=\"$('#message_new').reset();\">\n";
echo " <input type='button' class='btn' style='margin-top: 15px;' value='CLOSE' onclick=\"$('#message_new_layer').fadeOut(200);\">\n";
echo " <input type='submit' class='btn' style='float: right; margin-top: 15px;' value='SEND' xtitle='Ctrl + Enter'>\n";
echo " </center>\n";
echo " </span>\n";
echo " </form>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</div>\n";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-messages']."</b></td>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-messages']."</b><br><br></td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo " <input type='button' class='btn' value='".$text['button-send']."' onclick=\"window.location='message_send.php';\">\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-new-message']."' onclick=\"$('#message_new_layer').fadeIn(200); $('#message_new_to').focus();\" value='".$text['button-new-message']."'>\n";
/*
if (permission_exists('message_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
@@ -180,86 +159,117 @@
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='messages.php?show=all';\">\n";
}
}
*/
echo " <a href='messages_log.php'><input type='button' class='btn' alt=\"".$text['button-log']."\" value=\"".$text['button-log']."\"></a>\n";
/*
echo " <input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
*/
echo " </td>\n";
echo " </form>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<form method='post' action=''>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
if (is_array($messages)) {
$x = 0;
foreach($messages as $row) {
if ($x == 0) {
echo " <th style='width:30px;'>\n";
echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n";
echo " </th>\n";
echo th_order_by('message_type', $text['label-message_type'], $order_by, $order);
echo th_order_by('message_direction', $text['label-message_direction'], $order_by, $order);
echo th_order_by('message_date', $text['label-message_date'], $order_by, $order);
echo th_order_by('message_from', $text['label-message_from'], $order_by, $order);
echo th_order_by('message_to', $text['label-message_to'], $order_by, $order);
echo th_order_by('message_text', $text['label-message_text'], $order_by, $order);
echo " <td class='list_control_icons'>";
echo " &nbsp;\n";
echo " </td>\n";
echo "</tr>\n";
}
if (permission_exists('message_edit')) {
$tr_link = "href='message_edit.php?id=".escape($row['message_uuid'])."'";
}
echo "<tr ".$tr_link.">\n";
//echo " <td valign='top' class=''>".escape($row['user_uuid'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
echo " <input type='checkbox' name=\"messages[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
echo " <input type='hidden' name=\"messages[$x][message_uuid]\" value='".escape($row['message_uuid'])."' />\n";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_type'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_direction'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_date'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_from'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_to'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['message_text'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_media_type'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_media_url'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_media_content'])."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_json'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('message_edit')) {
echo "<a href='message_edit.php?id=".escape($row['message_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
}
if (permission_exists('message_delete')) {
echo "<button type='submit' class='btn btn-default list_control_icon' name=\"messages[$x][action]\" alt='".$text['button-delete']."' value='delete'><span class='glyphicon glyphicon-remove'></span></button>";
}
echo " </td>\n";
echo "</tr>\n";
$x++;
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $messages);
} //end if results
echo "<tr>\n";
echo "<td colspan='8' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
echo " &nbsp;";
echo " </td>\n";
echo " <th width='25%'>Contacts</th>\n";
echo " <th width='75%'>Messages</th>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</form>\n";
echo " <tr>\n";
echo " <td id='contacts' valign='top'>...</td>\n";
echo " <td id='thread' valign='top' style='border-color: #c5d1e5; border-style: solid; border-width: 0 1px 1px 1px; padding: 15px;'>...</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br /><br />";
//js to load messages for clicked number
echo "<script>\n";
echo " var contacts_refresh = 10000;\n";
echo " var thread_refresh = 5000;\n";
echo " var timer_contacts;\n";
echo " var timer_thread;\n";
echo " function refresh_contacts() {\n";
echo " clearTimeout(timer_contacts);\n";
echo " $('#contacts').load('messages_contacts.php', function(){\n";
echo " timer_contacts = setTimeout(refresh_contacts, contacts_refresh);\n";
echo " });\n";
echo " }\n";
echo " function load_thread(number) {\n";
echo " clearTimeout(timer_thread);\n";
echo " $('#thread').load('messages_thread.php?number=' + encodeURIComponent(number), function(){\n";
echo " $('#thread_messages').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
echo " $('span#thread_bottom')[0].scrollIntoView(true);\n"; //others
//note: the order of the above two lines matters!
echo " if ($('#message_new_layer').is(':hidden')) {\n";
echo " $('#message_text').focus();\n";
echo " }\n";
echo " timer_thread = setTimeout(refresh_thread_start, thread_refresh, number);\n";
echo " });\n";
echo " }\n";
echo " function refresh_thread(number, onsent) {\n";
echo " $('#thread_messages').load('messages_thread.php?refresh=true&number=' + encodeURIComponent(number), function(){\n";
echo " $('#thread_messages').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
echo " $('span#thread_bottom')[0].scrollIntoView(true);\n"; //others
//note: the order of the above two lines matters!
echo " if ($('#message_new_layer').is(':hidden')) {\n";
echo " $('#message_text').focus();\n";
echo " }\n";
echo " if (onsent != 'true') {\n";
echo " timer_thread = setTimeout(refresh_thread, thread_refresh, number);\n";
echo " }\n";
echo " });\n";
echo " }\n";
//refresh controls
echo " function refresh_contacts_stop() {\n";
echo " clearTimeout(timer_contacts);\n";
echo " document.getElementById('contacts_refresh_state').innerHTML = \"<img src='resources/images/refresh_paused.png' style='width: 16px; height: 16px; border: none; margin-top: 1px; cursor: pointer;' onclick='refresh_contacts_start();' alt='".$text['label-refresh_enable']."' title='".$text['label-refresh_enable']."'>\";\n";
echo " }\n";
echo " function refresh_contacts_start() {\n";
echo " if (document.getElementById('contacts_refresh_state')) {\n";
echo " document.getElementById('contacts_refresh_state').innerHTML = \"<img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick='refresh_contacts_stop();' alt='".$text['label-refresh_pause']."' title='".$text['label-refresh_pause']."'>\";\n";
echo " refresh_contacts();\n";
echo " }\n";
echo " }\n";
echo " function refresh_thread_stop(number) {\n";
echo " clearTimeout(timer_thread);\n";
echo " document.getElementById('thread_refresh_state').innerHTML = \"<img src='resources/images/refresh_paused.png' style='width: 16px; height: 16px; border: none; margin-top: 1px; cursor: pointer;' onclick='refresh_thread_start(\" + number + \");' alt='".$text['label-refresh_enable']."' title='".$text['label-refresh_enable']."'>\";\n";
echo " }\n";
echo " function refresh_thread_start(number) {\n";
echo " if (document.getElementById('thread_refresh_state')) {\n";
echo " document.getElementById('thread_refresh_state').innerHTML = \"<img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick='refresh_thread_stop(\" + number + \");' alt='".$text['label-refresh_pause']."' title='".$text['label-refresh_pause']."'>\";\n";
echo " refresh_thread(number);\n";
echo " }\n";
echo " }\n";
//define form submit function
echo " $('#message_new').submit(function(event) {\n";
echo " event.preventDefault();\n";
echo " $.ajax({\n";
echo " url: 'message_send.php',\n";
echo " type: 'POST',\n";
echo " data: $('#message_new').serialize(),\n";
echo " success: function(){\n";
echo " document.getElementById('message_new').reset();\n";
echo " $('#message_new_layer').fadeOut(400);\n";
echo " refresh_contacts();\n";
echo " }\n";
echo " });\n";
echo " });\n";
echo " refresh_contacts();\n";
echo "</script>\n";
unset($messages, $message, $numbers, $number);
//include the footer
require_once "resources/footer.php";

View File

@@ -0,0 +1,139 @@
<?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 the list
$since = date("Y-m-d H:i:s", strtotime("-24 hours"));
$sql = "select message_direction, message_from, message_to, contact_uuid from v_messages ";
$sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
//$sql .= "and message_date >= '".$since."' ";
$sql .= "order by message_date desc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$messages = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
//parse out numbers
if (is_array($messages) && sizeof($messages) != 0) {
$numbers = [];
foreach($messages as $message) {
$number_from = preg_replace('{[\D]}', '', $message['message_from']);
$number_to = preg_replace('{[\D]}', '', $message['message_to']);
if (!in_array($number_from, $numbers)) {
$numbers[] = $number_from;
}
if (!in_array($number_to, $numbers)) {
$numbers[] = $number_to;
}
switch ($message['message_direction']) {
case 'inbound': $contact[$number_from]['contact_uuid'] = $message['contact_uuid']; break;
case 'outbound': $contact[$number_to]['contact_uuid'] = $message['contact_uuid']; break;
}
unset($number_from, $number_to);
}
}
//get contact details, if uuid available
if (is_array($contact) && sizeof($contact) != 0) {
foreach ($contact as $number => $field) {
if (is_uuid($field['contact_uuid'])) {
$sql = "select contact_name_given, contact_name_family from v_contacts ";
$sql .= "where contact_uuid = '".$field['contact_uuid']."' ";
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_NAMED);
if (is_array($row) && sizeof($row) != 0) {
$contact[$number]['contact_name_given'] = $row['contact_name_given'];
$contact[$number]['contact_name_family'] = $row['contact_name_family'];
}
unset($prep_statement, $sql);
}
else {
unset($contact[$number]);
}
}
}
//get destinations and remove from numbers array
$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'];
}
}
unset ($prep_statement, $sql, $row, $record);
$numbers = array_diff($numbers, $destinations);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//contacts list
if (is_array($numbers) && sizeof($numbers) != 0) {
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
foreach($numbers as $number) {
echo " <tr><td valign='top' class='".$row_style[$c]."' onclick=\"load_thread('".urlencode($number)."');\">";
if ($contact[$number]['contact_name_given'] != '' || $contact[$number]['contact_name_family'] != '') {
echo " <i>".$contact[$number]['contact_name_given'].' '.$contact[$number]['contact_name_family'].'</i>';
echo "<span style='float: right; font-size: 65%; line-height: 60%; margin-top: 5px; margin-left: 5px;'>".format_phone($number).'</span>';
}
else {
echo " ".format_phone($number);
}
echo "</td></tr>\n";
$c = $c == 0 ? 1 : 0;
}
echo "</table>\n";
echo "<center>\n";
echo " <span id='contacts_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick=\"refresh_contacts_stop();\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span> ";
echo "</center>\n";
}
?>

View File

@@ -0,0 +1,274 @@
<?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')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$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;
}
}
}
//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 .= ") ";
}
//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';
}
}
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".$search;
if ($_GET['show'] == "all" && permission_exists('message_all')) {
$param .= "&show=all";
}
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
$offset = $rows_per_page * $page;
//get the list
$sql = "select * 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;
}
}
$sql .= "order by message_date desc ";
$sql .= "limit $rows_per_page offset $offset ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$messages = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//define the checkbox_toggle function
echo "<script type=\"text/javascript\">\n";
echo " function checkbox_toggle(item) {\n";
echo " var inputs = document.getElementsByTagName(\"input\");\n";
echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
echo " if (inputs[i].type === 'checkbox') {\n";
echo " if (document.getElementById('checkbox_all').checked == true) {\n";
echo " inputs[i].checked = true;\n";
echo " }\n";
echo " else {\n";
echo " inputs[i].checked = false;\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-messages']."</b><br><br></td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo " <a href='messages.php'><input type='button' class='btn' value='".$text['button-back']."'></a>\n";
if (permission_exists('message_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='messages_log.php?show=all';\">\n";
}
}
echo " <input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
echo " </td>\n";
echo " </form>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<form method='post' action=''>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
if (is_array($messages)) {
$x = 0;
foreach($messages as $row) {
if ($x == 0) {
echo " <th style='width:30px;'>\n";
echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n";
echo " </th>\n";
echo th_order_by('message_type', $text['label-message_type'], $order_by, $order);
echo th_order_by('message_direction', $text['label-message_direction'], $order_by, $order);
echo th_order_by('message_date', $text['label-message_date'], $order_by, $order);
echo th_order_by('message_from', $text['label-message_from'], $order_by, $order);
echo th_order_by('message_to', $text['label-message_to'], $order_by, $order);
echo th_order_by('message_text', $text['label-message_text'], $order_by, $order);
echo " <td class='list_control_icons'>";
echo " &nbsp;\n";
echo " </td>\n";
echo "</tr>\n";
}
if (permission_exists('message_edit')) {
$tr_link = "href='message_edit.php?id=".escape($row['message_uuid'])."'";
}
echo "<tr ".$tr_link.">\n";
//echo " <td valign='top' class=''>".escape($row['user_uuid'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
echo " <input type='checkbox' name=\"messages[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
echo " <input type='hidden' name=\"messages[$x][message_uuid]\" value='".escape($row['message_uuid'])."' />\n";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>";
switch ($row['message_type']) {
case 'sms': echo $text['label-sms']; break;
case 'mms': echo $text['label-mms']; break;
case 'chat': echo $text['label-chat']; break;
}
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>";
switch ($row['message_direction']) {
case "inbound": echo $text['label-inbound']; break;
case "outbound": echo $text['label-outbound']; break;
}
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_date'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape(format_phone($row['message_from']))."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape(format_phone($row['message_to']))."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['message_text'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('message_edit')) {
echo "<a href='message_edit.php?id=".escape($row['message_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
}
if (permission_exists('message_delete')) {
echo "<a href='message_delete.php?id=".escape($row['message_uuid'])."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
}
echo " </td>\n";
echo "</tr>\n";
$x++;
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $messages);
} //end if results
echo "<tr>\n";
echo "<td colspan='8' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
echo " &nbsp;";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</form>\n";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>

View File

@@ -0,0 +1,161 @@
<?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;
//get from messages
$since = date("Y-m-d H:i:s", strtotime("-24 hours"));
$sql = "select * from v_messages ";
$sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
//$sql .= "and message_date >= '".$since."' ";
$sql .= "and (message_from like '%".$number."' or message_to like '%".$number."') ";
$sql .= "order by message_date asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$messages = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset ($prep_statement, $sql);
//css styles
?>
<style>
.message-bubble {
display: block;
padding: 10px;
border: 1px solid;
margin-bottom: 10px;
}
.message-bubble-em {
margin-right: 10%;
border-radius: 0px 20px 20px 20px;
border-color: #cffec7;
background-color: #ecffe9;
}
.message-bubble-me {
margin-left: 10%;
border-radius: 20px 20px 0px 20px;
border-color: #cbf0ff;
background-color: #e5f7ff;
}
.message-bubble-when {
font-size: 65%;
line-height: 60%;
}
</style>
<?php
if (!$refresh) {
echo "<div id='thread_messages' style='max-height: 400px; overflow: auto;'>\n";
}
//output messages
if (is_array($messages) && sizeof($messages) != 0) {
foreach ($messages as $message) {
echo "<span class='message-bubble message-bubble-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
echo str_replace("\n",'<br />',$message['message_text'])."<br />\n";
echo "<span class='message-bubble-when'>".format_when_local($message['message_date'])."</span>\n";
echo "</span>\n";
//parse from inbound message
if ($message['message_direction'] == 'inbound') {
$message_from = $message['message_to'];
}
}
echo " <span id='thread_bottom'></span>\n";
}
if (!$refresh) {
echo "</div>\n";
if (permission_exists('message_add')) {
//output input form
echo "<form id='message_compose'>\n";
echo "<input type='hidden' name='message_type' value='sms'>\n";
echo "<input type='hidden' name='message_from' value='".$message_from."'>\n";
echo "<input type='hidden' name='message_to' value='".$number."'>\n";
echo "<textarea class='formfld' id='message_text' name='message_text' style='width: 100%; max-width: 100%; height: 40px; border: 1px solid #cbcbcb; resize: vertical; padding: 5px 8px; margin-top: 10px;' placeholder='Enter Response...'></textarea>";
echo "<span style='position: relative;'>\n";
echo " <center>\n";
echo " <input type='reset' class='btn' style='float: left; margin-top: 15px;' value='CLEAR' onclick=\"$('#message_text').focus();\">\n";
echo " <span id='thread_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick=\"refresh_thread_stop('".$number."');\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span> ";
echo " <input type='submit' class='btn' style='float: right; margin-top: 15px;' value='SEND' title='Ctrl + Enter'>\n";
echo " </center>\n";
echo "</span>\n";
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";
echo " url: 'message_send.php',\n";
echo " type: 'POST',\n";
echo " data: $('#message_compose').serialize(),\n";
echo " success: function(){\n";
echo " document.getElementById('message_compose').reset();\n";
echo " if ($('#message_new_layer').is(':hidden')) {\n";
echo " $('#message_text').focus();\n";
echo " }\n";
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";
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B