Example #1
0
 public function importLogs()
 {
     // Scan for new logs that haven't been processed before and import them into the log table
     // Make sure not to get dupes, even if there's a crash (how?)
     $coreFields = array('uuid' => 1, 'accountcode' => 1, 'caller_id_number' => 1, 'destination_number' => 1, 'context' => 1, 'duration' => 1, 'start_stamp' => 1, 'answer_stamp' => 1, 'end_stamp' => 1, 'billsec' => 1, 'hangup_cause' => 1, 'channel_name' => 1, 'bridge_channel' => 1);
     Kohana::log('debug', 'scandir: ' . Kohana::config('calls.scandir'));
     $callFiles = glob(rtrim(Kohana::config('calls.scandir'), '/') . '/' . 'Master.csv.*', GLOB_MARK);
     foreach ($callFiles as $callFile) {
         $recordCount = 0;
         $recordsInserted = 0;
         $recordsErrored = 0;
         $recordsDup = 0;
         $callFileHistory = new CallsFiles();
         $callFileHistory->filename = $callFile;
         // Save before we start so we can see if we crash. Also lets us calc how long it took.
         $callFileHistory->save();
         if (($callFileHandle = fopen($callFile, "r")) !== FALSE) {
             while (($callRecord = fgetcsv($callFileHandle, 2000, ",")) !== FALSE) {
                 $corecdr = array();
                 $extracdr = array();
                 $numFields = count($callRecord);
                 $recordCount++;
                 $insertCall = new Calls();
                 Kohana::log('debug', "{$numFields} fields in record {$recordCount}");
                 for ($field = 0; $field < $numFields; $field = $field + 2) {
                     if (isset($coreFields[$callRecord[$field]])) {
                         $corecdr[$callRecord[$field]] = $callRecord[$field + 1];
                     } else {
                         $extracdr[$callRecord[$field]] = $callRecord[$field + 1];
                     }
                 }
                 $corecdr['custom_fields'] = $extracdr;
                 $insertCall->synchronizeWithArray($corecdr);
                 try {
                     $insertCall->save();
                     $recordsInserted++;
                 } catch (Exception $e) {
                     if (preg_match('/Duplicate entry/', $e->getMessage())) {
                         $recordsDup++;
                     } else {
                         $recordsErrored++;
                     }
                     Kohana::log('debug', 'Insert of Call Log Failed. UUID: ' . $corecdr['uuid'] . 'Message: ' . $e->getMessage());
                 }
                 Kohana::log('debug', 'Call Log: ' . print_r($corecdr, true));
                 Kohana::log('debug', 'Call Log: ' . print_r($extracdr, true));
             }
             fclose($callFileHandle);
         }
         // Update the history adter we have processed the file.
         $callFileHistory->records_processed = $recordCount;
         $callFileHistory->records_inserted = $recordsInserted;
         $callFileHistory->records_errored = $recordsErrored;
         $callFileHistory->records_dup = $recordsDup;
         $callFileHistory->save();
     }
 }
Example #2
0
 public function testQuote()
 {
     $calls = new Calls();
     $request = new \App_Webservice_Types_Request_QuoteRequest();
     $request->id = 1;
     $response = $calls->quote($request);
     $this->assertType('App_Webservice_Types_Response_QuoteResponse', $response);
     $this->assertType('string', $response->quote->wording);
     $this->assertType('string', $response->quote->author);
 }
Example #3
0
        $tmp["status"] = $call["status"];
        $tmp["createdAt"] = $call["created_at"];
        array_push($response["calls"], $tmp);
    }
    echoRespnse(200, $response);
});
/**
 * Listing single call of particual user
 * method GET
 * url /calls/:id
 * Will return 404 if the call doesn't belongs to user
 */
$app->get('/calls/:id', 'authenticate', function ($call_id) {
    global $user_id;
    $response = array();
    $db = new Calls();
    // fetch call
    $result = $db->getCall($call_id, $user_id);
    if ($result != NULL) {
        $response["error"] = false;
        $response["id"] = $result["id"];
        $response["call"] = $result["call"];
        $response["status"] = $result["status"];
        $response["createdAt"] = $result["created_at"];
        echoRespnse(200, $response);
    } else {
        $response["error"] = true;
        $response["message"] = "The requested resource doesn't exists";
        echoRespnse(404, $response);
    }
});
Example #4
0
        }
        // Optional Authentication:
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_USERPWD, "username:password");
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
        //timeout in seconds
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }
    public function getRest($url)
    {
        $response = file_get_contents($url);
        return $response;
    }
}
/*Casa*/
//$url = "localhost:8080/YaxaRepositories/yaxaws/API/V1/greenclick/importProducts";
/*Trabajo*/
$url = "localhost/YaxaRepositories/yaxaws/API/V1/Yaxaco/getProducts";
$data = array('category' => 6, 'noSearch' => array('krono_code', 'iatai'), 'patternSearch' => 'video', 'qty' => 10);
$a = new Calls();
$string = $a->CallAPIbyCurl("POST", $url, $data);
//echo "<pre>";
$da = json_decode($string);
$v = json_decode($da);
var_dump($v);
//echo "</pre>";
Example #5
0
     $data['draw'] = 1;
     $data['recordsTotal'] = 100;
     $data['recordsFiltered'] = 100;
     $data['data'] = $calls->get_calls_table_data();
     header('Content-Type: application/json');
     echo json_encode($data);
     die;
 }
 if ($_GET['act'] == 'get_calls_data_weekday') {
     if (!isset($_GET['period'])) {
         $period = 'lifetime';
     } else {
         $period = $_GET['period'];
     }
     require '../classes/dashboard/Calls.php';
     $calls = new Calls();
     $calls->setPeriod($period);
     if ($period == 'custom') {
         $calls->setCustomPeriod($_REQUEST['from'], $_REQUEST['to']);
     }
     $data = $calls->get_weekday_stats();
     header('Content-Type: application/json');
     echo json_encode($data);
     die;
 }
 ////////////////////////////////////////////////////////////////////////////
 // Get leads statistics data
 ////////////////////////////////////////////////////////////////////////////
 if ($_GET['act'] === 'get_leads_data') {
     if (!isset($_GET['period'])) {
         $period = 'lifetime';