| <?php |
| |
| |
| const MsgRecordInstructions = "m-1012"; |
| const MsgMenuRecordInstructions = "m-1009"; |
| const MsgBranchConfigError = "m-1120"; |
| const MsgRecordSaved = "m-1452"; |
| const MsgRecordCanceled = "m-1306"; |
| const MsgContinueRecording = "m-2196"; |
| const MsgNoPhone = "m-1494"; |
| const MsgERROR = "m-1080"; |
| |
| |
| function CreateReadCommand(string $Message, array $Values): string { |
| $FormattedValues = implode(",", $Values); |
| return "read={$Message}={$FormattedValues}"; |
| } |
| |
| |
| |
| function record_play(string $RecordPath): string { |
| return "id_list_message=f-{$RecordPath}&" . MenuRecord(); |
| } |
| |
| function record_ok(string $token, string $RecordPath, string $GetPhone, string $GoToFolderAndPlay, string $ymApi): string { |
| $folderMove = isset($_GET["folder_move"]) ? $_GET["folder_move"] : "/personalMessages"; |
| $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); |
| $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); |
| CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); |
| $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; |
| file_get_contents($url); |
| unset($_SESSION["IfRecorded"]); |
| return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| } |
| |
| function record_ok_and_run_tzintuk(string $token, string $RecordPath, string $GetPhone, string $GoToFolderAndPlay, string $ymApi): string { |
| $folderMove = isset($_GET["folder_move"]) ? $_GET["folder_move"] : "/personalMessages"; |
| $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); |
| $encodedTarget = urlencode("ivr2:{$folderMove}/Phone/{$GetPhone}"); |
| CheckIfFolderExists($token, $encodedTarget, $ymApi, $GoToFolderAndPlay); |
| $url = "{$ymApi}FileAction?token={$token}&action=move&what={$encodedWhat}&target={$encodedTarget}"; |
| file_get_contents($url); |
| RunTzintuk($token, $GetPhone, $ymApi); |
| unset($_SESSION["IfRecorded"]); |
| return "id_list_message=" . MsgRecordSaved . "&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| } |
| |
| function record_again(string $hangupInsertFile, $RecordName): string { |
| $_SESSION["IfRecorded"] = "yes"; |
| $recordValues = [ |
| "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile |
| ]; |
| return CreateReadCommand(MsgRecordInstructions, $recordValues); |
| } |
| |
| function record_cancel(string $token, string $RecordPath, string $GoToFolderAndPlay, string $ymApi): string { |
| $encodedWhat = urlencode("ivr2:{$RecordPath}.wav"); |
| $url = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedWhat}"; |
| file_get_contents($url); |
| unset($_SESSION["IfRecorded"]); |
| return "id_list_message=" . MsgRecordCanceled . "&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| } |
| |
| function continue_recording(string $hangupInsertFile, $RecordName): string { |
| $_SESSION["IfRecorded"] = "yes"; |
| $recordValuesContinue = [ |
| "Record", "", "record", "/ApiTempFiles", $RecordName, "no", $hangupInsertFile, "yes" |
| ]; |
| return CreateReadCommand(MsgContinueRecording, $recordValuesContinue); |
| } |
| |
| |
| $recordFunctions = [ |
| "1" => "record_play", |
| "2" => "record_ok_and_run_tzintuk", |
| "3" => "record_again", |
| "4" => "record_cancel", |
| "5" => "continue_recording", |
| ]; |
| |
| function RecordFunc(string $hangupInsertFile): string { |
| $_SESSION["IfRecorded"] = "yes"; |
| $recordValues = [ |
| "Record", "", "record", "/ApiTempFiles", "", "no", $hangupInsertFile |
| ]; |
| return CreateReadCommand(MsgRecordInstructions, $recordValues); |
| } |
| |
| function MenuRecord (): string { |
| if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { |
| $_SESSION["IfRecorded"] = "no"; |
| } |
| |
| $menuRecordValues = [ |
| "MenuRecord", "", "1", "", "", "NO", "", "", "", "", "", "", "", "", "no" |
| ]; |
| return CreateReadCommand(MsgMenuRecordInstructions, $menuRecordValues); |
| } |
| |
| function RunTzintuk(string $token, string $GetPhone, string $ymApi) { |
| $callerId = isset($_GET["tzintuk_your_id"]) ? $_GET["tzintuk_your_id"] : null; |
| $TzintukTimeOut = isset($_GET["tzintuk_timeout"]) ? $_GET["tzintuk_timeout"] : null; |
| $url = "{$ymApi}RunTzintuk?token={$token}&phones=tzl:{$GetPhone}&callerId={$callerId}&TzintukTimeOut={$TzintukTimeOut}"; |
| file_get_contents($url); |
| } |
| |
| function CheckIfFolderExists(string $token, string $encodedTarget, string $ymApi, string $GoToFolderAndPlay) { |
| $url = "{$ymApi}CheckIfFileExists?token={$token}&path={$encodedTarget}/ext.ini"; |
| |
| $ch = curl_init($url); |
| curl_setopt_array($ch, [ |
| CURLOPT_RETURNTRANSFER => true, |
| CURLOPT_TIMEOUT => 10, |
| ]); |
| |
| $response = curl_exec($ch); |
| |
| if (curl_errno($ch)) { |
| $error_message = 'cURL Error'; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } else { |
| $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| if ($http_code == 200) { |
| |
| $result = json_decode($response, true); |
| |
| |
| if ($result !== null && isset($result['fileExists'])) { |
| |
| |
| if ($result['fileExists'] == false) { |
| $OpenFolder = "{$ymApi}UpdateExtension?token={$token}&path={$encodedTarget}"; |
| file_get_contents($OpenFolder); |
| $DeleteExtFile = "{$ymApi}FileAction?token={$token}&action=delete&what={$encodedTarget}/ext.ini"; |
| file_get_contents($DeleteExtFile); |
| } |
| } else { |
| $error_message = "Invalid JSON response or 'file' field not found/incorrect format Response"; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } |
| } else { |
| $error_message = "HTTP Error: {$http_code} Response: {$response}"; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } |
| } |
| |
| curl_close($ch); |
| } |
| |
| |
| $ymApi = "https://www.call2all.co.il/ym/api/"; |
| |
| $ApiDID = isset($_GET["ApiDID"]) ? $_GET["ApiDID"] : null; |
| $pass = isset($_GET["pass"]) ? $_GET["pass"] : null; |
| $ApiCallID = isset($_GET["ApiCallId"]) ? $_GET["ApiCallId"] : null; |
| $ApiExtension = isset($_GET["ApiExtension"]) ? $_GET["ApiExtension"] : null; |
| $ApiWhat = isset($_GET["what"]) ? $_GET["what"] : null; |
| $PlayStop = isset($_GET["PlayStop"]) ? $_GET["PlayStop"] : null; |
| |
| if (!$ApiDID || !$pass || !$ApiDID || !$ApiExtension || !$ApiWhat) { |
| echo "id_list_message=" . MsgBranchConfigError; |
| exit; |
| } |
| |
| |
| $token = urldecode("{$ApiDID}:{$pass}"); |
| |
| $ApiWhatFile = $ApiWhat && $ApiExtension ? str_replace("ivr2:/{$ApiExtension}/", "", $ApiWhat) : null; |
| $ApiWhatFile = $ApiWhatFile ? substr($ApiWhatFile, 0, strrpos($ApiWhatFile, ".")) : null; |
| $GoToPlayStop = $PlayStop ? $PlayStop - 5000 : null; |
| $GoToFolderAndPlay = "/{$ApiExtension},{$ApiWhatFile},{$GoToPlayStop}"; |
| |
| |
| if (isset($_GET["hangup_insert_file"]) && $_GET["hangup_insert_file"] == "yes") { |
| $hangupInsertFile = "yes"; |
| }else{ |
| $hangupInsertFile = ""; |
| } |
| |
| |
| if (isset($_GET["hangup_send_tzuntuk"]) && $_GET["hangup_send_tzuntuk"] == "yes") { |
| $hangupSendTzintuk = "yes"; |
| }else{ |
| $hangupSendTzintuk = ""; |
| } |
| |
| |
| $GetFileInfo = "{$ymApi}GetFile?token={$token}&what=" . urlencode($ApiWhat); |
| |
| |
| $ch = curl_init($GetFileInfo); |
| curl_setopt_array($ch, [ |
| CURLOPT_RETURNTRANSFER => true, |
| CURLOPT_TIMEOUT => 10, |
| ]); |
| |
| $response = curl_exec($ch); |
| |
| if (curl_errno($ch)) { |
| $error_message = 'cURL Error'; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } else { |
| $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| if ($http_code == 200) { |
| |
| $result = json_decode($response, true); |
| |
| |
| if ($result !== null && isset($result['file']) && is_array($result['file'])) { |
| |
| |
| if ($result['file']['phone'] !== null) { |
| $GetPhone = $result['file']['phone']; |
| } else { |
| echo "id_list_message=" . MsgNoPhone . "&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } |
| |
| } else { |
| $error_message = "Invalid JSON response or 'file' field not found/incorrect format Response"; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } |
| } else { |
| $error_message = "HTTP Error: {$http_code} Response: {$response}"; |
| echo "id_list_message=" . MsgERROR . ".noop-{$error_message}&go_to_folder_and_play={$GoToFolderAndPlay}"; |
| exit; |
| } |
| } |
| |
| curl_close($ch); |
| |
| if (isset($_GET["hangup"]) && isset($_GET["Record"])) { |
| if ($hangupInsertFile == "yes") { |
| |
| if ($hangupSendTzintuk == "yes") { |
| record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| }else{ |
| record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| } |
| }else{ |
| record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); |
| } |
| exit; |
| |
| }else{ |
| |
| exit; |
| } |
| |
| session_id($ApiCallID); |
| session_start(); |
| |
| |
| if (!isset($_GET["Record"])) { |
| |
| echo RecordFunc($hangupInsertFile); |
| exit; |
| |
| }else{ |
| |
| $RecordPath = str_replace(".wav", "", $_GET["Record"]); |
| $RecordName = str_replace("/ApiTempFiles" . "/", "", $RecordPath); |
| } |
| |
| |
| if (isset($_SESSION["IfRecorded"]) && $_SESSION["IfRecorded"] == "yes") { |
| |
| echo MenuRecord(); |
| |
| exit; |
| } |
| |
| |
| if (isset($_GET["MenuRecord"])) { |
| |
| $menuRecordOption = $_GET["MenuRecord"]; |
| |
| $optionsParam = "menu_record_options_" . $menuRecordOption; |
| |
| if (isset($_GET[$optionsParam])) { |
| $optionValue = $_GET[$optionsParam]; |
| |
| if (function_exists($optionValue) || $optionValue == "noop") { |
| if ($optionValue == "record_play") { |
| echo record_play($RecordPath); |
| } elseif ($optionValue == "record_ok") { |
| echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| } elseif ($optionValue == "record_ok_and_run_tzintuk") { |
| echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| } elseif ($optionValue == "record_again") { |
| echo record_again($hangupInsertFile, $RecordName); |
| } elseif ($optionValue == "record_cancel") { |
| echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); |
| } elseif ($optionValue == "continue_recording") { |
| echo continue_recording($hangupInsertFile, $RecordName); |
| } elseif ($optionValue == "noop") { |
| echo MenuRecord(); |
| } |
| } |
| } else { |
| if (array_key_exists($menuRecordOption, $recordFunctions)) { |
| $functionToCall = $recordFunctions[$menuRecordOption]; |
| if ($functionToCall == "record_play") { |
| echo record_play($RecordPath); |
| } elseif ($functionToCall == "record_ok") { |
| echo record_ok($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| } elseif ($functionToCall == "record_ok_and_run_tzintuk") { |
| echo record_ok_and_run_tzintuk($token, $RecordPath, $GetPhone, $GoToFolderAndPlay, $ymApi); |
| } elseif ($functionToCall == "record_again") { |
| echo record_again($hangupInsertFile, $RecordName); |
| } elseif ($functionToCall == "record_cancel") { |
| echo record_cancel($token, $RecordPath, $GoToFolderAndPlay, $ymApi); |
| } elseif ($functionToCall == "continue_recording") { |
| echo continue_recording($hangupInsertFile, $RecordName); |
| } |
| }else{ |
| echo MenuRecord(); |
| } |
| } |
| } |
| |
| ?> |