/** * Returns an array containing the selected details of a single message * * @param array Message object from twilio api * @param string sid of message * @param string the contact associated with the message * * @return array */ function getMessageArray($message, $sid, $contact) { $result = PluginData::sqlQuery("SELECT * FROM messages WHERE call_sid='{$sid}'"); if (count($result) == 0) { $result = insertMissingMessage($message, $sid); } return array('id' => $result[0]["id"], 'sid' => $sid, 'contact' => $contact, 'num_media' => $message->num_media, 'media' => $message->media, 'caller' => $message->from, 'created' => $message->date_created, 'status' => $result[0]["status"], 'archived' => $result[0]["archived"], 'body' => $message->body); }
public function setup() { $json['success'] = true; $json['message'] = ''; try { $currentSchemaVersion = OpenVBX::schemaVersion(); $upgradingToSchemaVersion = OpenVBX::getLatestSchemaVersion(); $sqlPath = VBX_ROOT . '/sql-updates/'; $updates = scandir($sqlPath); $files = array(); foreach ($updates as $i => $update) { if (preg_match('/^(\\d+).sql$/', $update)) { $rev = intval(str_replace('.sql', '', $update)); $files[$rev] = $update; } } ksort($files); $files = array_slice($files, $currentSchemaVersion); $tplvars = array('originalVersion' => $currentSchemaVersion, 'version' => $upgradingToSchemaVersion, 'updates' => $files); foreach ($files as $file) { $sql = @file_get_contents($sqlPath . $file); if (empty($sql)) { throw new UpgradeException("Unable to read update: {$file}", 1); } foreach (explode(";", $sql) as $stmt) { $stmt = trim($stmt); if (!empty($stmt)) { PluginData::sqlQuery($stmt); } } } } catch (Exception $e) { $json['success'] = false; $json['message'] = $e->getMessage(); $json['step'] = $e->getCode(); } $json['tplvars'] = $tplvars; echo json_encode($json); }
public static function query($sql) { return PluginData::sqlQuery($sql); }
public function setup() { $json['success'] = true; $json['message'] = ''; try { $currentSchemaVersion = OpenVBX::schemaVersion(); $upgradingToSchemaVersion = OpenVBX::getLatestSchemaVersion(); $upgradeScriptPath = VBX_ROOT . '/updates/'; $updates = scandir($upgradeScriptPath); $updatesToRun = array(); // Collect all files named numerically in /updates and key sort the list of updates foreach ($updates as $i => $update) { if (preg_match('/^(\\d+).(sql|php)$/', $update, $matches)) { $updateExtension = $matches[2]; $rev = $matches[1]; $updatesToRun[$rev] = array('type' => $updateExtension, 'filename' => $update, 'revision' => $rev); } } ksort($updatesToRun); // Cut the updates by the current schema version. $updatesToRun = array_slice($updatesToRun, $currentSchemaVersion); $tplvars = array('originalVersion' => $currentSchemaVersion, 'version' => $upgradingToSchemaVersion, 'updates' => $updatesToRun); foreach ($updatesToRun as $updateToRun) { $file = $updateToRun['filename']; $type = $updateToRun['type']; $revision = $updateToRun['revision']; switch ($type) { case 'php': require_once $upgradeScriptPath . $file; $runUpdateMethod = "runUpdate_{$revision}"; if (!function_exists($runUpdateMethod)) { throw new UpgradeException("runUpdate method missing from {$file}: {$runUpdateMethod}"); } call_user_func($runUpdateMethod); break; case 'sql': $sql = @file_get_contents($upgradeScriptPath . $file); if (empty($sql)) { throw new UpgradeException("Unable to read update: {$file}", 1); } foreach (explode(";", $sql) as $stmt) { $stmt = trim($stmt); if (!empty($stmt)) { PluginData::sqlQuery($stmt); } } break; } } flush_minify_caches(); } catch (Exception $e) { $json['success'] = false; $json['message'] = $e->getMessage(); $json['step'] = $e->getCode(); } $json['tplvars'] = $tplvars; echo json_encode($json); }
<?php include "functions.php"; $account = OpenVBX::getAccount(); $phoneNumbers = getAccountPhoneNumbers($account); //detect if the address book is present, if so then we can attempt to lookup contacts if (count(PluginData::sqlQuery("select * from addressbook_contacts limit 1")) == 1) { $address_book = True; } else { $address_book = False; } $to = filter_var($_REQUEST['to'], FILTER_SANITIZE_NUMBER_FLOAT); $from = filter_var($_REQUEST['from'], FILTER_SANITIZE_NUMBER_FLOAT); $content = filter_var($_REQUEST['content'], FILTER_SANITIZE_STRING); // if the to field is set, we're viewing a single thried if ($to != "") { $function = "contact"; if ($content != "" && $from != "") { sendSMS($account, $to, $from, $content); } } $limit = 100; // Set a limit of items per page $threads_per_page = 20; // limit of items to display for page, contacts or messages $threads_offset = filter_var($_REQUEST['offset'], FILTER_SANITIZE_NUMBER_INT); //offset from begining of messages to display if ($threads_offset == "") { $threads_offset = 0; //default offset value }