Exemplo n.º 1
0
function people_dial(&$call)
{
    global $db;
    $extension = $call->get_extension();
    $callerId = $call->get_cid();
    $callerIdFull = $call->get_cidFull();
    $query = "select ChanType, username, VoIPAccount.ID " . "  from People, VoIPAccount, VoIPChannel " . " where People.Extension = {$extension} " . "   and VoIPAccount.People_Extension = {$extension} " . "   and VoIPAccount.VoIPChannel_ID = VoIPChannel.ID " . "   and VoIPAccount.Enable = true ";
    $query = $db->query($query);
    check_db($query);
    if ($row = $query->fetchRow(DB_FETCHMODE_ORDERED)) {
        $dialStr = $row[0] . "/" . $row[1] . "-" . $row[2];
        while ($row = $query->fetchRow(DB_FETCHMODE_ORDERED)) {
            $dialStr .= "&";
            $dialStr .= $row[0] . "/" . $row[1] . "-" . $row[2];
        }
        agi_log(DEBUG_DEBUG, "people_dial(): {$callerId} : " . "{$extension} -> '{$dialStr}'");
        return agi_call($call, $dialStr, "r", 0, 0);
    }
    return agi_notFound($call);
}
Exemplo n.º 2
0
function outside_dial(&$call)
{
    global $db;
    // 1°) trouver à quel réseau appartient l'extension
    $net = outside_getNetworkId($call);
    agi_log(DEBUG_DEBUG, 'outside_dial() : ' . $call->get_extension() . " -> {$net}");
    if ($net < 0) {
        return agi_notFound($call);
    }
    // 2°) faut-il annoncer le prix à l'utilisateur ?
    //	faut-il continuer plus cher ?
    $query = "select P.Announce, P.AskHigherCost " . "  from People_PrePay_Settings as P  " . " where People_Extension = " . $call->get_responsable();
    $query = $db->query($query);
    check_db($query);
    if (!($row = $query->fetchRow(DB_FETCHMODE_ORDERED))) {
        // not found : paramètre par défaut :
        $askHigher = false;
        $announce = true;
        agi_log(DEBUG_INFO, "outside_dial() : account not found");
    } else {
        $askHigher = $row[1];
        $announce = $row[0];
    }
    agi_log(DEBUG_DEBUG, "outside_dial() : {$announce} - {$askHigher}");
    // 3°) récupérer la liste des providers et leur prix
    $query = "select N.Name, N.channel, P.ConnectionPrice, P.Price, " . "       P.RmDigits, P.AddDigits, N.DialOpts " . " from  NetworkProvider as N, Price as P, " . "\t NetworkTimeZone_details as T " . " where P.Network_ID = {$net} " . "   and P.NetworkProvider_ID = N.ID " . "   and P.NetworkTimeZone_ID = T.NetworkTimeZone_ID " . "   and (" . date("i") . " between start_min and end_min )" . "   and (" . date("G") . " between start_hour and end_hour )" . "   and (" . date("n") . " between start_month and end_month )" . "   and (" . date("j") . " between start_dom and end_dom )" . "   and (" . date("w") . " between start_dow and end_dow )" . " order by P.Price, P.ConnectionPrice ";
    $query = $db->query($query);
    check_db($query);
    /*	0 : name	
     *	1 : channel
     *	2 : priceConn
     *	3 : price/min
     *	4 : RmDigits
     *	5 : AddDigits
     *	6 : DialOpts
     */
    if ($query->numRows() == 0) {
        return agi_notFound($call);
    }
    $provider = $query->fetchRow(DB_FETCHMODE_ORDERED);
    // 4°) on tente d'appeler
    $isFirst = true;
    // première tentative au prix le plus bas
    while (($isFirst || $askHigher) && $provider != NULL) {
        $price = $provider[3];
        // 5°) on annonce au besoin :
        if ($announce) {
            agi_play_soundSet(SOUNDSET_PRICE_ANNOUNCE, "");
            agi_sayNumber(ceil($price * 100));
            agi_play_soundSet(SOUNDSET_CURRENCY, "");
        }
        // on teste l'un à la suite de l'autre tout les providers
        // qui ont le même prix d'appel
        while ($provider[3] == $price && $provider != NULL) {
            $callStr = $provider[1] . $provider[5] . substr($call->get_extension(), $provider[4]);
            agi_log(DEBUG_DEBUG, "outside_dial() : trying : {$callStr}");
            $result = agi_call($call, $callStr, $provider[6], $provider[2], $provider[3], false);
            if ($result >= 0 || $call->get_lastTryStatus() != "CHANUNAVIL") {
                // succeed
                return $result;
            }
            $provider = $query->fetchRow(DB_FETCHMODE_ORDERED);
        }
        // annonce qu'il est impossible d'effectuer l'appel au prix
        // annoncé précédement
        agi_play_soundSet(SOUNDSET_UNAVAIL_AT_PRICE, "");
        $first = false;
        // téléchargement du provider suivant
        $provider = $query->fetchRow(DB_FETCHMODE_ORDERED);
    }
    agi_logCall($call, 0, 0, "NOT ROUTABLE");
    return -1;
}