Beispiel #1
0
include_once LIB_DIR . DIRECTORY_SEPARATOR . 'definitions.php';
setlocale(LC_NUMERIC, 'en_US');
$options['action'] = isset($options['action']) ? $options['action'] : '';
define('VOIP_CACHE_DIR', isset($options['cache-dir']) ? $options['cache-dir'] : SYS_DIR . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'voip' . DIRECTORY_SEPARATOR . 'cache');
$estimate = new Estimate(SqlProvider::getInstance());
$db_buffor = new VoipDbBuffor(SqlProvider::getInstance());
switch (strtolower($options['action'])) {
    case 'estimate':
        if (!isset($options['caller'])) {
            die("Caller phone number isn't set.");
        }
        if (!isset($options['callee'])) {
            die("Callee phone number isn't set.");
        }
        try {
            $call_time = $estimate->getMaxCallTime($options['caller'], $options['callee']);
            // if debug mode is set print value else change to miliseconds before print
            echo array_key_exists('debug', $options) ? $call_time . PHP_EOL : $call_time * 1000;
        } catch (Exception $e) {
            echo $e->getMessage();
        }
        break;
    case 'account':
        if (isset($options['file'])) {
            $fh = isset($options['file']) ? fopen($options['file'], 'r') : fopen('php://stdin', 'r');
            $error = array();
            $i = 0;
            while ($f_line = fgets($fh)) {
                ++$i;
                if (($tmp = $db_buffor->appendCdr($f_line)) != 1) {
                    $error[] = array('line' => $i, 'desc' => $tmp);