function writeFile($data) { $file = fopen("../data/connections.json", "w") or die(generateResponse("error", "Error writing to file.")); fwrite($file, $data); fclose($file); }
function handleLogResourceRequest($path) { $resourceLogFile = sys_get_temp_dir() . "/resource-log"; $newData = "\n" . $path; // Documentation says that appends are atomic. file_put_contents($resourceLogFile, $newData, FILE_APPEND); generateResponse($path); }
function finaorecentposts($uid) { $data = array(); $query = mysql_query("select user_finao_id from fn_user_finao where userid={$uid} AND finao_activestatus=1 AND Iscompleted=0 order by user_finao_id DESC"); if (mysql_num_rows($query) > 0) { $sno = 0; while ($obj = mysql_fetch_object($query)) { //echo "select uploaddetail_id, uploadtype, upload_text from fn_uploaddetails where upload_sourcetype=37 AND upload_sourceid=$obj->user_finao_id order by uploaddetail_id DESC"; //echo "\n"; $qry = mysql_fetch_object(mysql_query("select uploaddetail_id, uploadtype, upload_text from fn_uploaddetails where upload_sourcetype=37 AND upload_sourceid={$obj->user_finao_id} order by uploaddetail_id DESC")); if ($qry->uploadtype != '') { if ($qry->uploadtype == 62) { $data[$sno]['message'] = $qry->upload_text; $data[$sno]['image_name'] = ""; $data[$sno]['caption'] = ""; } else { if ($qry->uploadtype == 34) { $imgdata = mysql_fetch_object(mysql_query("select uploadfile_name, caption from fn_images where upload_id={$qry->uploaddetail_id} order by image_id DESC limit 1")); $data[$sno]['message'] = ""; $data[$sno]['image_name'] = $imgdata->uploadfile_name; $data[$sno]['caption'] = $imgdata->caption; } else { if ($qry->uploadtype == 35) { $viddata = mysql_fetch_object(mysql_query("select uploadfile_name, caption from fn_videos where upload_id={$qry->uploaddetail_id} order by image_id DESC")); $data[$sno]['message'] = ""; $data[$sno]['image_name'] = $viddata->uploadfile_name; $data[$sno]['caption'] = $viddata->caption; } } } $data[$sno]['uploaddetail_id'] = $qry->uploaddetail_id; $sno++; } } $response = generateResponse(TRUE, NULL, $data); echo json_encode($response); } else { // show error } }
function handleIncreaseResourceCountCommand($path) { $resourceCountFile = sys_get_temp_dir() . "/resource-count"; $resourceCount = getState($resourceCountFile); $pieces = explode(" ", $resourceCount); $count = 0; if (count($pieces) == 2 && $pieces[0] == $path) { $count = 1 + $pieces[1]; } else { $count = 1; } file_put_contents($resourceCountFile, $path . " " . $count); generateResponse($path); }
<?php require 'vendor/autoload.php'; use Slim\Slim; $default_thinQ_callback = array('type' => 'sip', 'detail' => array('id' => '19196356566', 'domain' => 'wap.thinq.com', 'headers' => array('thinQid' => '11001', 'thinQtoken' => '0c82a54f22f775a3ed8b97b2dea74036'))); $app = new Slim(); $app->get('/', function () { echo "welcome to twiml callback server"; }); $app->post('/get_response', function () use($app, $default_thinQ_callback) { $from = $app->request()->params('From'); $to = $app->request()->params('To'); $callSid = $app->request()->params('CallSid'); $accountSid = $app->request()->params('AccountSid'); $app->response->headers->set("Content-Type", 'application/xml'); $response = generateResponse($to, $default_thinQ_callback); if (!$response) { echo "<Response>\n\t\t\t\t<Say>\n\t\t\t\t\tSorry, an error has been occurred. Please try again later.\n\t\t\t\t</Say>\n\t\t\t</Response>"; } echo $response; }); $app->run(); function generateResponse($to, $details) { $twiml_response = new Services_Twilio_Twiml(); $twiml_response->say("We are trying to connect you to our customer system."); if ($details['type'] == 'phone') { $twiml_response->dial($details['detail']['id'], array('callerId' => $to)); } else { if ($details['type'] == 'sip') { $headers = '';
function settings_tagnote($authuserid) { $client = new SoapClient(host); $sessionId = $client->login(username, password); $customerId = ''; $query = mysql_query("select mageid from fn_users where userid='" . $authid . "' limit 1"); if (mysql_num_rows($query) > 0) { $obj = mysql_fetch_object($query); $customerId = $obj->mageid; $requestData = array('tagnote_id' => $customerId, 'finao' => 'testing, testing, 123'); $tagnoteData = $client->call($sessionId, 'finao.update', array($requestData)); echo $json = json_encode($tagnoteData); } else { getStatusCode(401); $response = generateResponse(FALSE, UNUTHORISED_USER); echo json_encode($response); } }