Exemplo n.º 1
0
function Service_Create_TrunkConfig($activation_code)
{
    $DBHandle = DbConnect();
    $table_instance = new Table();
    if (!$DBHandle) {
        write_log(LOGFILE_API_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . " ERROR CONNECT DB");
        return array('500', ' ERROR - CONNECT DB ');
    }
    list($accountnumber, $password) = preg_split("{_}", $activation_code, 2);
    $QUERY = "SELECT cc.username, cc.credit, cc.status, cc.id, cc.id_didgroup, cc.tariff, cc.vat, ct.gmtoffset, cc.voicemail_permitted, " . "cc.voicemail_activated, cc_card_group.users_perms, cc.currency " . "FROM cc_card cc LEFT JOIN cc_timezone AS ct ON ct.id = cc.id_timezone LEFT JOIN cc_card_group ON cc_card_group.id=cc.id_group " . "WHERE cc.username = '******' AND cc.uipass = '******'";
    $res = $DBHandle->Execute($QUERY);
    if (!$res) {
        return array('400', ' ERROR - AUTHENTICATE CODE');
    }
    $row[] = $res->fetchRow();
    $card_id = $row[0][3];
    if (!$card_id || $card_id < 0) {
        return array('400', ' ERROR - AUTHENTICATE CODE');
    }
    $QUERY_IAX = "SELECT iax.id, iax.username, iax.secret, iax.disallow, iax.allow, iax.type, iax.host, iax.context FROM cc_iax_buddies iax WHERE iax.id_cc_card = {$card_id}";
    $QUERY_SIP = "SELECT sip.id, sip.username, sip.secret, sip.disallow, sip.allow, sip.type, sip.host, sip.context FROM cc_sip_buddies sip WHERE sip.id_cc_card = {$card_id}";
    $iax_data = $table_instance->SQLExec($DBHandle, $QUERY_IAX);
    $sip_data = $table_instance->SQLExec($DBHandle, $QUERY_SIP);
    //Additonal parameters
    $additional_sip = explode("|", SIP_ADDITIONAL_PARAMETERS);
    $additional_iax = explode("|", IAX_ADDITIONAL_PARAMETERS);
    // SIP
    $Config_output = "#PROTOCOL:SIP#\n#SIP-TRUNK-CONFIG-START#\n[trunkname]\n";
    $Config_output .= "username="******"\n";
    $Config_output .= "type=friend\n";
    $Config_output .= "secret=" . $sip_data[0][2] . "\n";
    $Config_output .= "host=" . $sip_data[0][6] . "\n";
    $Config_output .= "context=" . $sip_data[0][7] . "\n";
    $Config_output .= "disallow=all\n";
    $Config_output .= "allow=" . SIP_IAX_INFO_ALLOWCODEC . "\n";
    if (count($additional_sip) > 0) {
        for ($i = 0; $i < count($additional_sip); $i++) {
            $Config_output .= trim($additional_sip[$i]) . chr(10);
        }
    }
    $Config_output .= "#SIP-TRUNK-CONFIG-END#\n\n";
    // IAX
    $Config_output .= "#PROTOCOL:IAX#\n#IAX-TRUNK-CONFIG-START#\n[trunkname]\n";
    $Config_output .= "username="******"\n";
    $Config_output .= "type=friend\n";
    $Config_output .= "secret=" . $iax_data[0][2] . "\n";
    $Config_output .= "host=" . $iax_data[0][6] . "\n";
    $Config_output .= "context=" . $iax_data[0][7] . "\n";
    $Config_output .= "disallow=all\n";
    $Config_output .= "allow=" . SIP_IAX_INFO_ALLOWCODEC . "\n";
    if (count($additional_iax) > 0) {
        for ($i = 0; $i < count($additional_iax); $i++) {
            $Config_output .= trim($additional_iax[$i]) . chr(10);
        }
    }
    $Config_output .= "#IAX-TRUNK-CONFIG-END#\n\n";
    return array($Config_output, '200 -- Config OK');
}
Exemplo n.º 2
0
function agi_confx_title($handle = null)
{
    if (empty($handle)) {
        $handle = DbConnect();
    }
    $instance_table = new Table();
    $QUERY = "SELECT id, group_title, group_description, SUBSTR(group_title,9,3)+0 AS idorder FROM cc_config_group WHERE group_title like '%agi-conf%' ORDER BY idorder";
    $result = $instance_table->SQLExec($handle, $QUERY);
    if (is_array($result)) {
        $num_cur = count($result);
        for ($i = 0; $i < $num_cur; $i++) {
            $config_group_id = $result[0][0];
            $group_title[] = $result[$i][1];
            $description = $result[0][2];
        }
    }
    foreach ($group_title as $value) {
        $agi_number[] = (int) substr($value, 8);
    }
    $len_agi_array = sizeof($agi_number);
    $agi_conf_number = $len_agi_array + 1;
    for ($i = 1; $i <= $len_agi_array; $i++) {
        if ($i != $agi_number[$i - 1]) {
            $agi_conf_number = $i;
            break;
        }
    }
    $config_group = array();
    $config_group[0] = "agi-conf" . $agi_conf_number;
    $config_group[1] = $config_group_id;
    $config_group[2] = $description;
    $config_group[3] = $agi_number[0];
    return $config_group;
}
Exemplo n.º 3
0
 function Status($security_key, $id)
 {
     $status = 'null';
     $uniqueid = '';
     $DBHandle = DbConnect();
     $instance_table = new Table();
     $QUERY = "SELECT status, uniqueid FROM cc_callback_spool WHERE id='{$id}'";
     $callback_data = $instance_table->SQLExec($DBHandle, $QUERY);
     if (!is_array($callback_data) || count($callback_data) == 0) {
         // FAIL SELECT
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR SELECT -> \n QUERY=" . $QUERY);
         sleep(2);
         return array($uniqueid, 'result=null', ' ERROR - SELECT DB');
     }
     $status = $callback_data[0][0];
     $uniqueid = $callback_data[0][1];
     return array($uniqueid, 'result=' . $status, " - Callback request found {$QUERY}");
 }
echo gettext("Value");
?>
</th>
                    <th class="tableBody" style="padding: 2px;" align="center" width="50%"><?php 
echo gettext("Description");
?>
</th>
                    <th class="tableBody" style="padding: 2px;" align="center" width="5%"><?php 
echo gettext("Group");
?>
</th>
                </tr>
<?php 
$instance_table = new Table();
$QUERY = "SELECT config_title, config_key, config_value, config_description FROM cc_config WHERE config_group_title = 'agi-conf" . $config_group[3] . "' ORDER BY id LIMIT 10";
$config = $instance_table->SQLExec($HD_Form->DBHandle, $QUERY);
$i = 0;
foreach ($config as $values) {
    $config_title = $values[0];
    $config_key = $values[1];
    $config_value = $values[2];
    $config_description = $values[3];
    if ($i % 2 == 0) {
        $bgcolor = "bgColor='#FCFBFB'";
    } else {
        $bgcolor = "bgColor='#F2F2EE'";
    }
    ?>
                <tr <?php 
    echo $bgcolor;
    ?>
Exemplo n.º 5
0
$currencies_list = get_currencies();
if (strlen($voucher) > 0) {
    if (is_numeric($voucher)) {
        sleep(2);
        $FG_VOUCHER_TABLE = "cc_voucher";
        $FG_VOUCHER_FIELDS = "voucher, credit, activated, tag, currency, expirationdate";
        $instance_sub_table = new Table($FG_VOUCHER_TABLE, $FG_VOUCHER_FIELDS);
        $FG_TABLE_CLAUSE_VOUCHER = "expirationdate >= CURRENT_TIMESTAMP AND activated='t' AND voucher='{$voucher}'";
        $list_voucher = $instance_sub_table->Get_list($HD_Form->DBHandle, $FG_TABLE_CLAUSE_VOUCHER, $order, $sens, null, null, $limite, $current_record);
        if ($list_voucher[0][0] == $voucher) {
            if (!isset($currencies_list[strtoupper($list_voucher[0][4])][2])) {
                $error_msg = '<font face="Arial, Helvetica, sans-serif" size="2" color="red"><b>' . gettext("System Error : the currency table is incomplete!") . '</b></font><br><br>';
            } else {
                $add_credit = $list_voucher[0][1] * $currencies_list[strtoupper($list_voucher[0][4])][2];
                $QUERY = "UPDATE cc_voucher SET activated='f', usedcardnumber='" . $_SESSION["pr_login"] . "', usedate=now() WHERE voucher='" . $voucher . "'";
                $result = $instance_sub_table->SQLExec($HD_Form->DBHandle, $QUERY, 0);
                $QUERY = "UPDATE cc_card SET credit=credit+'" . $add_credit . "' WHERE username='******'";
                $result = $instance_sub_table->SQLExec($HD_Form->DBHandle, $QUERY, 0);
                $error_msg = '<font face="Arial, Helvetica, sans-serif" size="2" color="green"><b>' . gettext("The voucher") . '(' . $voucher . ') ' . gettext("has been used, We added") . ' ' . $add_credit . ' ' . gettext("credit on your account!") . '</b></font><br><br>';
            }
        } else {
            $error_msg = '<font face="Arial, Helvetica, sans-serif" size="2" color="red"><b>' . gettext("This voucher doesn't exist !") . '</b></font><br><br>';
        }
    } else {
        $error_msg = '<font face="Arial, Helvetica, sans-serif" size="2" color="red"><b>' . gettext("The voucher should be a number !") . '</b></font><br><br>';
    }
}
if ($id != "" || !is_null($id)) {
    $HD_Form->FG_EDITION_CLAUSE = str_replace("%id", "{$id}", $HD_Form->FG_EDITION_CLAUSE);
}
if (!isset($form_action)) {
 $context = $A2B->config["callback"]['context_campaign_callback'];
 $id_server_group = $A2B->config["callback"]['id_server_group'];
 $priority = 1;
 $timeout = $A2B->config["callback"]['timeout'] * 1000;
 $application = '';
 //default callerid
 $callerid = '111111111';
 $cidgroupid = $phone["id_cid_group"];
 if ($A2B->config["database"]['dbtype'] == "postgres") {
     $QUERY = "SELECT cid FROM cc_outbound_cid_list WHERE activated = 1 AND outbound_cid_group = {$cidgroupid} ORDER BY RANDOM() LIMIT 1";
 } else {
     $QUERY = "SELECT cid FROM cc_outbound_cid_list WHERE activated = 1 AND outbound_cid_group = {$cidgroupid} ORDER BY RAND() LIMIT 1";
 }
 $instance_cid_table = new Table();
 echo "QUERY CID : " . $QUERY;
 $cidresult = $instance_cid_table->SQLExec($A2B->DBHandle, $QUERY);
 if (is_array($cidresult) && count($cidresult) > 0) {
     $callerid = $cidresult[0][0];
 }
 $account = $_SESSION["pr_login"];
 $uniqueid = MDP_NUMERIC(5) . '-' . MDP_STRING(7);
 $status = 'PENDING';
 $server_ip = 'localhost';
 $num_attempt = 0;
 $variable = "CALLED={$destination}|USERNAME={$phone['8']}|USERID={$phone['6']}|CBID={$uniqueid}|PHONENUMBER_ID=" . $phone['cc_phonenumber_id'] . "|CAMPAIGN_ID=" . $phone['cc_campaign_id'];
 $res = $instance_table->Add_table($A2B->DBHandle, "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}',  now(), '{$account}', '{$callerid}', '30000'", "uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout", "cc_callback_spool", "id");
 if (!$res) {
     if ($verbose_level >= 1) {
         echo "[Cannot insert the callback request in the spool!]";
     }
 } else {
Exemplo n.º 7
0
$A2B->load_conf($agi, NULL, 0, $idconfig);

write_log (LOGFILE_CRONT_INVOICE, basename(__FILE__) . ' line:' . __LINE__ . "[#### CRONT BILLING BEGIN ####]");

if (!$A2B->DbConnect()) {
	echo "[Cannot connect to the database]\n";
	write_log (LOGFILE_CRONT_INVOICE, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
	exit;
}

$instance_table = new Table();

// CHECK COUNT OF CARD ON WHICH APPLY THE SERVICE
$QUERY = 'SELECT count(*) FROM cc_card';

$result = $instance_table->SQLExec($A2B->DBHandle, $QUERY);
$nb_card = $result[0][0];
$nbpagemax = (ceil($nb_card / $groupcard));

if ($verbose_level >= 1)
	echo "===> NB_CARD : $nb_card - NBPAGEMAX:$nbpagemax\n";

if (!($nb_card > 0)) {
	if ($verbose_level >= 1)
		echo "[No card to run the Invoice Billing Service]\n";
	write_log (LOGFILE_CRONT_INVOICE, basename(__FILE__) . ' line:' . __LINE__ . "[No card to run the Invoice Billing service]");
	exit ();
}

if ($verbose_level >= 1)
	echo ("[Invoice Billing Service analyze cards on which to apply billing]");
Exemplo n.º 8
0
 *
 *
**/
include_once '../../lib/admin.defines.php';
include_once '../../lib/admin.module.access.php';
if (!has_rights(ACX_DASHBOARD)) {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
$checkdate = date("Y-m-d");
$DBHandle = DbConnect();
$QUERY_COUNT_CALL_ALL = "select terminatecauseid, count(*) from cc_call WHERE starttime >= TIMESTAMP('{$checkdate}') AND starttime <= CURRENT_TIMESTAMP GROUP BY terminatecauseid";
$QUERY_COUNT_CALL_BILL = "SELECT sum(sessiontime), sum(sessionbill), sum(buycost) FROM cc_call WHERE starttime>= TIMESTAMP('{$checkdate}') AND starttime <= CURRENT_TIMESTAMP ;";
$table = new Table('cc_call', '*');
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CALL_ALL);
$result_count_all = 0;
$result_count_answered = 0;
$result_count_noanswer = 0;
$result_count_cancelled = 0;
$result_count_congested = 0;
$result_count_busy = 0;
$result_count_chanunavail = 0;
foreach ($result as $res_row) {
    if ($res_row[0] == 1) {
        $result_count_answered = $res_row[1];
    }
    if ($res_row[0] == 2) {
        $result_count_busy = $res_row[1];
    }
    if ($res_row[0] == 3) {
Exemplo n.º 9
0
include '../lib/epayment/classes/order.php';
include '../lib/epayment/classes/currencies.php';
include '../lib/epayment/includes/general.php';
include '../lib/epayment/includes/html_output.php';
include '../lib/epayment/includes/configure.php';
include '../lib/epayment/includes/loadconfiguration.php';
$DBHandle_max = DbConnect();
$paymentTable = new Table();
if (DB_TYPE == "postgres") {
    $NOW_2MIN = " creationdate <= (now() - interval '2 minute') ";
} else {
    $NOW_2MIN = " creationdate <= DATE_SUB(NOW(), INTERVAL 2 MINUTE) ";
}
// Status - New 0 ; Proceed 1 ; In Process 2
$QUERY = "SELECT id, agent_id, amount, vat, paymentmethod, cc_owner, cc_number, cc_expires, creationdate, status, cvv, credit_card_type, currency " . " FROM cc_epayment_log_agent " . " WHERE id = " . $transactionID . " AND (status = 0 OR (status = 2 AND {$NOW_2MIN}))";
$transaction_data = $paymentTable->SQLExec($DBHandle_max, $QUERY);
$amount = $transaction_data[0][2];
//Update the Transaction Status to 1
$QUERY = "UPDATE cc_epayment_log_agent SET status = 2 WHERE id = " . $transactionID;
write_log(LOGFILE_EPAYMENT, basename(__FILE__) . ' line:' . __LINE__ . "- QUERY = {$QUERY}");
$paymentTable->SQLExec($DBHandle_max, $QUERY);
if (!is_array($transaction_data) && count($transaction_data) == 0) {
    write_log(LOGFILE_EPAYMENT, basename(__FILE__) . ' line:' . __LINE__ . "- transactionID={$transactionID}" . " ERROR INVALID TRANSACTION ID PROVIDED, TRANSACTION ID =" . $transactionID);
    exit;
} else {
    write_log(LOGFILE_EPAYMENT, basename(__FILE__) . ' line:' . __LINE__ . "- transactionID={$transactionID}" . " EPAYMENT RESPONSE: TRANSACTIONID = " . $transactionID . " FROM " . $transaction_data[0][4] . "; FOR CUSTOMER ID " . $transaction_data[0][1] . "; OF AMOUNT " . $transaction_data[0][2]);
}
$security_verify = true;
$transaction_detail = base64_encode(serialize($_POST));
$currencyObject = new currencies();
$currencies_list = get_currencies();
Exemplo n.º 10
0
          <?php 
    if ($popup_select) {
        ?>
                  <input type="hidden" name="popup_select" value="<?php 
        echo $popup_select;
        ?>
" />
          <?php 
    }
    ?>
          <td align="left" width="75%">
                <?php 
    $handle = DbConnect();
    $instance_table = new Table();
    $QUERY = "SELECT code, name FROM cc_iso639 order by code";
    $result = $instance_table->SQLExec($handle, $QUERY);
    if (is_array($result)) {
        $num_cur = count($result);
        for ($i = 0; $i < $num_cur; $i++) {
            $languages_list[$result[$i][0]] = array(0 => $result[$i][0], 1 => $result[$i][1]);
        }
    }
    ?>
                <select NAME="languages" size="1" class="form_input_select" onChange="form.submit()">
                    <?php 
    foreach ($languages_list as $key => $lang_value) {
        ?>
                    <option value='<?php 
        echo $lang_value[0];
        ?>
' <?php 
Exemplo n.º 11
0
     } else {
         $confirm_buy_did = 0;
     }
 } else {
     if ($confirm_buy_did != 4) {
         $confirm_buy_did = 0;
     }
 }
 if (is_numeric($voip_call) && $confirm_buy_did >= 2 && ($voip_call == 0 || $voip_call == 1 && strpos(substr($destination, strpos($destination, '@')), '.'))) {
     $instance_table_did_use = new Table();
     $validated = $voip_call == 1 ? 0 : 1;
     if ($voip_call == 0) {
         $destination = intval($destination) > 0 ? $destination : 'no valid';
     }
     $QUERY = "INSERT INTO cc_did_destination (activated, id_cc_card, id_cc_did, destination, priority, voip_call, validated) VALUES ('1', '" . $_SESSION["card_id"] . "', '" . $choose_did . "', '" . $destination . "', '1', '" . $voip_call . "', '{$validated}')";
     $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY, 0);
     if ($confirm_buy_did == 2) {
         $QUERY1 = "INSERT INTO cc_charge (id_cc_card, amount, chargetype, id_cc_did) " . "VALUES ('" . $_SESSION["card_id"] . "', '" . $rate . "', '2','" . $choose_did . "')";
         $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY1, 0);
         $QUERY1 = "UPDATE cc_did set iduser = "******"card_id"] . ",reserved=1 where id = '" . $choose_did . "'";
         $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY1, 0);
         $QUERY1 = "UPDATE cc_card set credit = credit -" . $rate . " where id = '" . $_SESSION["card_id"] . "'";
         $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY1, 0);
         $QUERY1 = "UPDATE cc_did_use set releasedate = now() where id_did = '" . $choose_did . "' and activated = 0";
         $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY1, 0);
         $QUERY1 = "INSERT INTO cc_did_use (activated, id_cc_card, id_did, month_payed) values ('1','" . $_SESSION["card_id"] . "','" . $choose_did . "', 1)";
         $result = $instance_table_did_use->SQLExec($HD_Form->DBHandle, $QUERY1, 0);
     }
     $date = date("D M j G:i:s T Y", time());
     $message = "\n\n" . gettext("The following Destinaton for your DID has been added:") . "\n\n";
     $message .= "{$QUERY}";
Exemplo n.º 12
0
				"'$calledstation', 1,   1.2000, 1,  '1856254697', 0.40000, 0, $cardid, $id_ratecard, $destination) \n";
		
		if (strlen($qry)==0) {
			$qry = $c_qry_header.$c_qry_value;
		} else {
			$qry .= ' , '.$c_qry_value;
		}
		
		if (($nb_cdr % $nb_cdr_flush) == 0) {
			if ($verbose)
				echo "Processing CDR generation for $nb_cdr_flush CDRs \n";
			
			if ($verbose >=3) echo "CDR No=$nb_cdr --> $qry\n";
			
			$A2B -> DBHandle -> Execute('BEGIN;');
			$instance_table -> SQLExec ($A2B -> DBHandle, $qry);
			$A2B -> DBHandle -> Execute('COMMIT;');
			$qry = '';
		}
		
	}
}

if (strlen($qry)>0) {
	echo "CDR No=$nb_cdr --> $qry\n";
	$A2B -> DBHandle -> Execute('BEGIN;');
	$instance_table -> SQLExec ($A2B -> DBHandle, $qry);
	$A2B -> DBHandle -> Execute('COMMIT;');
}

if ($verbose)
Exemplo n.º 13
0
}
$verbose_level = 0;
$groupcard = 5000;
$A2B = new A2Billing();
$A2B->load_conf($agi, NULL, 0, $idconfig);
write_log(LOGFILE_CRONT_AUTOREFILL, basename(__FILE__) . ' line:' . __LINE__ . "[#### BATCH BEGIN ####]");
if (!$A2B->DbConnect()) {
    echo "[Cannot connect to the database]\n";
    write_log(LOGFILE_CRONT_AUTOREFILL, basename(__FILE__) . ' line:' . __LINE__ . "[Cannot connect to the database]");
    exit;
}
//$A2B -> DBHandle
$instance_table = new Table();
// CHECK NUMBER OF CARD
$QUERY = 'SELECT count(*) FROM cc_card WHERE autorefill=1 AND ((typepaid=0 AND initialbalance>0 AND credit<initialbalance) OR (typepaid=1))';
$result = $instance_table->SQLExec($A2B->DBHandle, $QUERY);
$nb_card = $result[0][0];
$nbpagemax = ceil($nb_card / $groupcard);
if ($verbose_level >= 1) {
    echo "===> NB_CARD : {$nb_card} - NBPAGEMAX:{$nbpagemax}\n";
}
if (!($nb_card > 0)) {
    if ($verbose_level >= 1) {
        echo "[No card to run the Auto Refill]\n";
    }
    write_log(LOGFILE_CRONT_AUTOREFILL, basename(__FILE__) . ' line:' . __LINE__ . "[No card to run the Auto Refill]");
    exit;
}
if ($A2B->config["database"]['dbtype'] == "postgres") {
    $UNIX_TIMESTAMP = "date_part('epoch',";
} else {
Exemplo n.º 14
0
**/
include "lib/customer.defines.php";
include "lib/customer.module.access.php";
include "lib/customer.smarty.php";
include "lib/epayment/includes/configure.php";
include "lib/epayment/includes/html_output.php";
include "./lib/epayment/includes/general.php";
if (!has_rights(ACX_ACCESS)) {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
$inst_table = new Table();
$QUERY = "SELECT username, credit, lastname, firstname, address, city, state, country, zipcode, phone, email, fax, lastuse, activated, status, " . "freetimetocall, label, packagetype, billingtype, startday, id_cc_package_offer, cc_card.id, currency,cc_card.useralias,UNIX_TIMESTAMP(cc_card.creationdate) creationdate  FROM cc_card " . "LEFT JOIN cc_tariffgroup ON cc_tariffgroup.id=cc_card.tariff LEFT JOIN cc_package_offer ON cc_package_offer.id=cc_tariffgroup.id_cc_package_offer " . "LEFT JOIN cc_card_group ON cc_card_group.id=cc_card.id_group WHERE username = '******' AND uipass = '******'";
$DBHandle = DbConnect();
$customer_res = $inst_table->SQLExec($DBHandle, $QUERY);
if (!$customer_res || !is_array($customer_res)) {
    echo gettext("Error loading your account information!");
    exit;
}
$customer_info = $customer_res[0];
if ($customer_info[14] != "1" && $customer_info[14] != "8") {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
$customer = $_SESSION["pr_login"];
getpost_ifset(array('posted', 'Period', 'frommonth', 'fromstatsmonth', 'tomonth', 'tostatsmonth', 'fromday', 'fromstatsday_sday', 'fromstatsmonth_sday', 'today', 'tostatsday_sday', 'tostatsmonth_sday', 'dsttype', 'sourcetype', 'clidtype', 'channel', 'resulttype', 'stitle', 'atmenu', 'current_page', 'order', 'sens', 'dst', 'src', 'clid', 'subscribe'));
$currencies_list = get_currencies();
$two_currency = false;
if (!isset($currencies_list[strtoupper($customer_info[22])][2]) || !is_numeric($currencies_list[strtoupper($customer_info[22])][2])) {
?>
</th>
					<th class="tableBody" style="padding: 2px;" align="center" width="50%"><?php 
echo gettext("Description");
?>
</th>
					<th class="tableBody" style="padding: 2px;" align="center" width="5%"><?php 
echo gettext("Group");
?>
</th>
				</tr>
<?php 
$DBHandle = DbConnect();
$instance_table = new Table();
$QUERY = "SELECT config_title,config_key,config_value,config_description from cc_config where config_group_id = 11 order by id limit 10";
$config = $instance_table->SQLExec($DBHandle, $QUERY);
$i = 0;
foreach ($config as $values) {
    $config_title = $values[0];
    $config_key = $values[1];
    $config_value = $values[2];
    $config_description = $values[3];
    if ($i % 2 == 0) {
        $bgcolor = "bgColor='#FCFBFB'";
    } else {
        $bgcolor = "bgColor='#F2F2EE'";
    }
    ?>
				
				<tr <?php 
    echo $bgcolor;
Exemplo n.º 16
0
                        $OPL = $key == $last_key ? '' : ' OR ';
                        if (is_array($value)) {
                            $rates_clauses .= " (destination BETWEEN '{$value['0']}' AND '{$value['1']}') {$OPL}";
                        } else {
                            $rates_clauses .= " destination = '{$value}' {$OPL}";
                        }
                    }
                }
                break;
            default:
                $rates_clauses .= " destination = '{$prefix}'";
                break;
        }
    }
    $QUERY = "SELECT {$id},id FROM cc_ratecard rc WHERE {$rates_clauses} GROUP BY destination";
    $table_rates->SQLExec($DBHandle, "INSERT IGNORE INTO cc_package_rate(package_id , rate_id) ({$QUERY})");
    Header("Location: A2B_package_manage_rates.php?id={$id}");
}
if (isset($addrate) && is_numeric($addrate)) {
    $DBHandle = DbConnect();
    $add_rate_table = new Table("cc_package_rate", "*");
    $fields = " package_id , rate_id";
    $values = " {$id} , {$addrate}";
    $add_rate_table->Add_table($DBHandle, $values, $fields);
    Header("Location: A2B_package_manage_rates.php?id={$id}");
}
if (isset($delrate) && is_numeric($delrate)) {
    $DBHandle = DbConnect();
    $del_rate_table = new Table("cc_package_rate", "*");
    $CLAUSE = " package_id = " . $id . " AND rate_id = {$delrate}";
    $del_rate_table->Delete_table($DBHandle, $CLAUSE);
Exemplo n.º 17
0
$FG_LIMITE_DISPLAY = $nb_display_lines;
$FG_NB_TABLE_COL = count($FG_TABLE_COL);
$FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL;
$FG_HTML_TABLE_TITLE = gettext($resulttitle);
if ($FG_DEBUG == 3) {
    echo "<br>Table : {$FG_TABLE_NAME} - Col_query : {$FG_COL_QUERY}";
}
if (is_null($order) || is_null($sens)) {
    $order = $FG_TABLE_DEFAULT_ORDER;
    $sens = $FG_TABLE_DEFAULT_SENS;
}
$instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY);
$list = $instance_table->Get_list($DBHandle, $FG_TABLE_CLAUSE, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page * $FG_LIMITE_DISPLAY, $sql_group, $caching_query);
if ($FILTER_COUNTRY) {
    $QUERY = 'SELECT DISTINCT destination FROM cc_prefix ORDER BY destination LIMIT 0, 1000';
    $country_list = $instance_table->SQLExec($DBHandle, $QUERY, 1, $caching_query);
}
$QUERY = "SELECT count(*) FROM (SELECT DISTINCT t7.destination, t1.dialprefix, t1.rateinitial FROM {$FG_TABLE_NAME} WHERE {$FG_TABLE_CLAUSE}" . $sql_group . ") as setprefix ";
$list_nrecord = $instance_table->SQLExec($DBHandle, $QUERY, 1, $caching_query);
$nb_record = $list_nrecord[0][0];
if ($nb_record <= $FG_LIMITE_DISPLAY) {
    $nb_record_max = 1;
} else {
    if ($nb_record % $FG_LIMITE_DISPLAY == 0) {
        $nb_record_max = intval($nb_record / $FG_LIMITE_DISPLAY);
    } else {
        $nb_record_max = intval($nb_record / $FG_LIMITE_DISPLAY) + 1;
    }
}
?>
<script language="JavaScript" type="text/JavaScript">
Exemplo n.º 18
0
include '../lib/agent.smarty.php';
if (!has_rights(ACX_SIGNUP)) {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
/***********************************************************************************/
getpost_ifset(array('NewSecret'));
$DBHandle = DbConnect();
//////$instance_sub_table = new Table('cc_callerid');
/////$QUERY = "INSERT INTO cc_callerid (id_cc_card, cid) VALUES ('".$_SESSION["card_id"]."', '".$add_callerid."')";
//////$result = $instance_sub_table -> SQLExec ($HD_Form -> DBHandle, $QUERY, 0);
if ($form_action == "ask-modif") {
    $instance_sub_table = new Table('cc_agent', "id");
    $QUERY = "UPDATE cc_agent SET secret= '" . $NewSecret . "' WHERE ( ID = " . $_SESSION["agent_id"] . "  ) ";
    $result = $instance_sub_table->SQLExec($DBHandle, $QUERY, 0);
}
$instance_table_agent_secret = new Table("cc_agent ", "secret");
$list_agent_secret = $instance_table_agent_secret->Get_list($DBHandle, "id=" . $_SESSION['agent_id'], "id", "ASC", null, null, null, null);
$secret = $list_agent_secret[0][0];
// #### HEADER SECTION
$smarty->display('main.tpl');
// #### HELP SECTION
echo $CC_help_secret_change . "<br>";
if ($form_action == "ask-modif") {
    if (is_array($result_check)) {
        ?>
    <script language="JavaScript">
    alert("<?php 
        echo gettext("Your secret is updated successfully.");
        ?>
Exemplo n.º 19
0
// #### TOP SECTION PAGE
$HD_Form->create_toppage($form_action);

$HD_Form->create_form($form_action, $list);

if ($form_action = "ask_edit") {
	$DBHandle = DbConnect();
	$instance_table = new Table();

	$QUERY_PHONENUMBERS = 'SELECT cc_campaign.id, cc_campaign.name,cc_campaign.status, cc_campaign.startingdate <= CURRENT_TIMESTAMP AS started ,cc_campaign.expirationdate <= CURRENT_TIMESTAMP AS expired  FROM cc_phonenumber , cc_phonebook , cc_campaign_phonebook, cc_campaign WHERE ';
	//JOIN CLAUSE
	$QUERY_PHONENUMBERS .= 'cc_phonenumber.id_phonebook = cc_phonebook.id AND cc_campaign_phonebook.id_phonebook = cc_phonebook.id AND cc_campaign_phonebook.id_campaign = cc_campaign.id ';
	//CAMPAIGN CLAUSE
	if ($id != null) // Exclude if null otherwise kills the list query
		$QUERY_PHONENUMBERS .= 'AND cc_phonenumber.id= ' . $id; // I've no idea under what conditions this should be included. Please review!
	$result = $instance_table->SQLExec($DBHandle, $QUERY_PHONENUMBERS);
	if ($result) {
		?>
	 	<br/>
	 	<br/>
		<table width="100%" class="editform_table1" >
		<tr>
			<th>
				<?php echo gettext("CAMPAIGN") ?> 
			</th>
			<th>
				<?php echo gettext("INFO") ?> 
			</th>
			<th>
				<?php echo gettext("STATUS") ?> 
			</th>
}
$FG_TABLE_CLAUSE .= "t1.username='******'";
if (strlen($FG_TABLE_CLAUSE) > 0) {
    $FG_TABLE_CLAUSE .= " AND ";
}
if ($invoice_type == 1) {
    $FG_TABLE_CLAUSE .= "t1.starttime >(Select CASE  WHEN max(cover_enddate) IS NULL THEN '0001-01-01 01:00:00' ELSE max(cover_enddate) END from cc_invoices WHERE cardid = " . $_SESSION["card_id"] . ")";
} else {
    $FG_TABLE_CLAUSE .= "t1.starttime >(Select cover_startdate  from cc_invoices where id ='{$id}') AND t1.stoptime <(Select cover_enddate from cc_invoices where id ='{$id}') ";
}
$_SESSION["pr_sql_export"] = "SELECT {$FG_COL_QUERY} FROM {$FG_TABLE_NAME} WHERE {$FG_TABLE_CLAUSE}";
$QUERY = "SELECT substring(t1.starttime,1,10) AS day, sum(t1.sessiontime) AS calltime, sum(t1.sessionbill) AS cost, count(*) as nbcall FROM {$FG_TABLE_NAME} WHERE " . $FG_TABLE_CLAUSE . "   GROUP BY substring(t1.starttime,1,10) ORDER BY day";
//extract(DAY from calldate)
//echo "$QUERY";
if (!$nodisplay) {
    $list_total_day = $instance_table->SQLExec($DBHandle, $QUERY);
}
//end IF nodisplay
// GROUP BY DESTINATION FOR THE INVOICE
$QUERY = "SELECT destination, sum(t1.sessiontime) AS calltime, \nsum(t1.sessionbill) AS cost, count(*) as nbcall FROM {$FG_TABLE_NAME} WHERE " . $FG_TABLE_CLAUSE . "  GROUP BY destination";
if (!$nodisplay) {
    $list_total_destination = $instance_table->SQLExec($DBHandle, $QUERY);
}
//end IF nodisplay
/************************************************ DID Billing Section *********************************************/
// Fixed + Dial = 0
// Fixed = 1
// Dail = 2
// Free = 3
// 1. Billing Type:: All DID Calls that have DID Type 0 and 2
if ($invoice_type == 1) {
Exemplo n.º 21
0
 public function rate_engine_calcultimeout(&$A2B, $credit, $K = 0)
 {
     global $agi;
     $rateinitial = a2b_round(abs($this->ratecard_obj[$K][12]));
     $initblock = $this->ratecard_obj[$K][13];
     $billingblock = $this->ratecard_obj[$K][14];
     $connectcharge = a2b_round(abs($this->ratecard_obj[$K][15]));
     $disconnectcharge = a2b_round(abs($this->ratecard_obj[$K][16]));
     $disconnectcharge_after = $this->ratecard_obj[$K][60];
     $announce_time_correction = $this->ratecard_obj[$K][61];
     $stepchargea = $this->ratecard_obj[$K][17];
     $chargea = a2b_round(abs($this->ratecard_obj[$K][18]));
     $timechargea = $this->ratecard_obj[$K][19];
     $billingblocka = $this->ratecard_obj[$K][20];
     $stepchargeb = $this->ratecard_obj[$K][21];
     $chargeb = a2b_round(abs($this->ratecard_obj[$K][22]));
     $timechargeb = $this->ratecard_obj[$K][23];
     $billingblockb = $this->ratecard_obj[$K][24];
     $stepchargec = $this->ratecard_obj[$K][25];
     $chargec = a2b_round(abs($this->ratecard_obj[$K][26]));
     $timechargec = $this->ratecard_obj[$K][27];
     $billingblockc = $this->ratecard_obj[$K][28];
     // ****************  PACKAGE PARAMETERS ****************
     $id_cc_package_offer = $this->ratecard_obj[$K][45];
     $id_rate = $this->ratecard_obj[$K][6];
     $initial_credit = $credit;
     // CHANGE THIS - ONLY ALLOW FREE TIME FOR CUSTOMER THAT HAVE MINIMUM CREDIT TO CALL A DESTINATION
     $this->freetimetocall_left[$K] = 0;
     $this->freecall[$K] = false;
     $this->package_to_apply[$K] = null;
     //CHECK THE PACKAGES TO APPLY TO THIS RATES
     if ($id_cc_package_offer != -1) {
         $query_pakages = "SELECT cc_package_offer.id, packagetype, billingtype, startday, freetimetocall " . "FROM cc_package_offer, cc_package_rate WHERE cc_package_offer.id = " . $id_cc_package_offer . " AND cc_package_offer.id = cc_package_rate.package_id AND cc_package_rate.rate_id = " . $id_rate . " ORDER BY packagetype ASC";
         $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[PACKAGE IN:{$query_pakages} ]");
         $table_packages = new Table();
         $result_packages = $table_packages->SQLExec($A2B->DBHandle, $query_pakages);
         $idx_pack = 0;
         if (!empty($result_packages)) {
             $package_selected = false;
             while (!$package_selected && $idx_pack < count($result_packages)) {
                 $freetimetocall = $result_packages[$idx_pack]["freetimetocall"];
                 $packagetype = $result_packages[$idx_pack]["packagetype"];
                 $billingtype = $result_packages[$idx_pack]["billingtype"];
                 $startday = $result_packages[$idx_pack]["startday"];
                 $id_cc_package_offer = $result_packages[$idx_pack][0];
                 $A2B->debug("[ID PACKAGE  TO APPLY={$id_cc_package_offer} - packagetype={$packagetype}]");
                 switch ($packagetype) {
                     // 0 : UNLIMITED PACKAGE
                     //IF PACKAGE IS "UNLIMITED" SO WE DON'T NEED TO CALCULATE THE USED TIMES
                     case 0:
                         $this->freecall[$K] = true;
                         $package_selected = true;
                         $this->package_to_apply[$K] = array("id" => $id_cc_package_offer, "label" => "Unlimited calls", "type" => $packagetype);
                         $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[Unlimited calls]");
                         break;
                         // 1 : FREE CALLS
                         //IF PACKAGE IS "NUMBER OF FREE CALLS"  AND WE CAN USE IT ELSE WE CHECK THE OTHERS PACKAGE LIKE FREE TIMES
                     // 1 : FREE CALLS
                     //IF PACKAGE IS "NUMBER OF FREE CALLS"  AND WE CAN USE IT ELSE WE CHECK THE OTHERS PACKAGE LIKE FREE TIMES
                     case 1:
                         if ($freetimetocall > 0) {
                             $number_calls_used = $A2B->number_free_calls_used($A2B->DBHandle, $A2B->id_card, $id_cc_package_offer, $billingtype, $startday);
                             if ($number_calls_used < $freetimetocall) {
                                 $this->freecall[$K] = true;
                                 $package_selected = true;
                                 $this->package_to_apply[$K] = array("id" => $id_cc_package_offer, "label" => "Number of Free calls", "type" => $packagetype);
                                 $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[Number of Free calls]");
                             }
                         }
                         break;
                         //2 : FREE TIMES
                     //2 : FREE TIMES
                     case 2:
                         // CHECK IF WE HAVE A FREETIME THAT CAN APPLY FOR THIS DESTINATION
                         if ($freetimetocall > 0) {
                             // WE NEED TO RETRIEVE THE AMOUNT OF USED MINUTE FOR THIS CUSTOMER ACCORDING TO BILLINGTYPE (Monthly ; Weekly) & STARTDAY
                             $this->freetimetocall_used = $A2B->FT2C_used_seconds($A2B->DBHandle, $A2B->id_card, $id_cc_package_offer, $billingtype, $startday);
                             $this->freetimetocall_left[$K] = $freetimetocall - $this->freetimetocall_used;
                             if ($this->freetimetocall_left[$K] < 0) {
                                 $this->freetimetocall_left[$K] = 0;
                             }
                             if ($this->freetimetocall_left[$K] > 0) {
                                 $package_selected = true;
                                 $this->package_to_apply[$K] = array("id" => $id_cc_package_offer, "label" => "Free minutes", "type" => $packagetype);
                                 $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[Free minutes - freetimetocall_used={$this->freetimetocall_used}]");
                             }
                         }
                         $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[Free minutes - Break (freetimetocall_left=" . $this->freetimetocall_left[$K] . ")]");
                         break;
                 }
                 $idx_pack++;
             }
         }
     }
     $credit -= $connectcharge;
     if ($disconnectcharge_after == 0) {
         $credit -= $disconnectcharge;
         //no disconnenct charge on timeout if disconnectcharge_after is set
     }
     $callbackrate = array();
     if ($A2B->mode == 'cid-callback' || $A2B->mode == 'all-callback') {
         $callbackrate['ri'] = $rateinitial;
         $callbackrate['ib'] = $initblock;
         $callbackrate['bb'] = $billingblock;
         $callbackrate['cc'] = $connectcharge;
         $callbackrate['dc'] = $disconnectcharge;
         $callbackrate['sc_a'] = $stepchargea;
         $callbackrate['tc_a'] = $timechargea;
         $callbackrate['c_a'] = $chargea;
         $callbackrate['bb_a'] = $billingblocka;
         $callbackrate['sc_b'] = $stepchargeb;
         $callbackrate['tc_b'] = $timechargeb;
         $callbackrate['c_b'] = $chargeb;
         $callbackrate['bb_b'] = $billingblockb;
         $callbackrate['sc_c'] = $stepchargec;
         $callbackrate['tc_c'] = $timechargec;
         $callbackrate['c_c'] = $chargec;
         $callbackrate['bb_c'] = $billingblockc;
     }
     $this->ratecard_obj[$K]['callbackrate'] = $callbackrate;
     $this->ratecard_obj[$K]['timeout'] = 0;
     $this->ratecard_obj[$K]['timeout_without_rules'] = 0;
     // used for the simulator
     $this->ratecard_obj[$K]['freetime_include_in_timeout'] = $this->freetimetocall_left[$K];
     // CHECK IF THE USER IS ALLOW TO CALL WITH ITS CREDIT AMOUNT
     /*
     Comment from Abdoulaye Siby
     This following "if" statement used to verify the minimum credit to call can be improved.
     This mininum credit should be calculated based on the destination, and the minimum billing block.
     */
     if ($credit < $A2B->agiconfig['min_credit_2call'] && !$this->freecall[$K] && $this->freetimetocall_left[$K] <= 0) {
         $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[NO ENOUGH CREDIT TO CALL THIS NUMBER - ERROR CT1]");
         return "ERROR CT1";
         //NO ENOUGH CREDIT TO CALL THIS NUMBER
     }
     // if ($rateinitial==0) return "ERROR RATEINITIAL($rateinitial)";
     $TIMEOUT = 0;
     $answeredtime_1st_leg = 0;
     if ($rateinitial <= 0) {
         $this->ratecard_obj[$K]['timeout'] = $A2B->agiconfig['maxtime_tocall_negatif_free_route'];
         $this->ratecard_obj[$K]['timeout_without_rules'] = $A2B->agiconfig['maxtime_tocall_negatif_free_route'];
         $TIMEOUT = $A2B->agiconfig['maxtime_tocall_negatif_free_route'];
         // 90 min
         if ($this->debug_st) {
             print_r($this->ratecard_obj[$K]);
         }
         return $TIMEOUT;
     }
     if ($this->freecall[$K]) {
         if ($this->package_to_apply[$K]["type"] == 0) {
             $this->ratecard_obj[$K]['timeout'] = $A2B->agiconfig['maxtime_tounlimited_calls'];
             // default : 90 min
             $TIMEOUT = $A2B->agiconfig['maxtime_tounlimited_calls'];
             $this->ratecard_obj[$K]['timeout_without_rules'] = $A2B->agiconfig['maxtime_tounlimited_calls'];
             $this->ratecard_obj[$K]['freetime_include_in_timeout'] = $A2B->agiconfig['maxtime_tounlimited_calls'];
         } else {
             $this->ratecard_obj[$K]['timeout'] = $A2B->agiconfig['maxtime_tofree_calls'];
             $TIMEOUT = $A2B->agiconfig['maxtime_tofree_calls'];
             $this->ratecard_obj[$K]['timeout_without_rules'] = $A2B->agiconfig['maxtime_tofree_calls'];
             $this->ratecard_obj[$K]['freetime_include_in_timeout'] = $A2B->agiconfig['maxtime_tofree_calls'];
         }
         if ($this->debug_st) {
             print_r($this->ratecard_obj[$K]);
         }
         return $TIMEOUT;
     }
     if ($credit < $A2B->agiconfig['min_credit_2call'] && $this->freetimetocall_left[$K] > 0) {
         $this->ratecard_obj[$K]['timeout'] = $this->freetimetocall_left[$K];
         $TIMEOUT = $this->freetimetocall_left[$K];
         $this->ratecard_obj[$K]['timeout_without_rules'] = $this->freetimetocall_left[$K];
         return $TIMEOUT;
     }
     // IMPROVE THE get_variable AND TRY TO RETRIEVE THEM ALL SOMEHOW
     if ($A2B->mode == 'callback') {
         $calling_party_rateinitial = $agi->get_variable('RI', true);
         $calling_party_initblock = $agi->get_variable('IB', true);
         $calling_party_billingblock = $agi->get_variable('BB', true);
         $calling_party_connectcharge = $agi->get_variable('CC', true);
         $calling_party_disconnectcharge = $agi->get_variable('DC', true);
         $calling_party_stepchargea = $agi->get_variable('SC_A', true);
         $calling_party_timechargea = $agi->get_variable('TC_A', true);
         $calling_party_stepchargeb = $agi->get_variable('SC_B', true);
         $calling_party_timechargeb = $agi->get_variable('TC_B', true);
         $calling_party_stepchargec = $agi->get_variable('SC_C', true);
         $calling_party_timechargec = $agi->get_variable('TC_C', true);
     }
     // 2 KIND OF CALCULATION : PROGRESSIVE RATE & FLAT RATE
     // IF FLAT RATE
     if (empty($chargea) || $chargea == 0 || empty($timechargea) || $timechargea == 0) {
         if ($A2B->mode == 'callback') {
             /*
             Comment from Abdoulaye Siby
             In all-callback or cid-callback mode, the number of minutes for the call must be calculated
             according to the rates of both legs of the call.
             */
             $credit -= $calling_party_connectcharge;
             $credit -= $calling_party_disconnectcharge;
             $num_min = $credit / ($rateinitial + $calling_party_rateinitial);
             //I think that the answered time is in seconds
             $answeredtime_1st_leg = intval($agi->get_variable('ANSWEREDTIME', true));
         } else {
             $num_min = $credit / $rateinitial;
         }
         if ($this->debug_st) {
             echo "num_min:{$num_min} ({$credit}/{$rateinitial})\n";
         }
         $num_sec = intval($num_min * 60) - $answeredtime_1st_leg;
         if ($this->debug_st) {
             echo "num_sec:{$num_sec} \n";
         }
         if ($billingblock > 0) {
             $mod_sec = $num_sec % $billingblock;
             $num_sec = $num_sec - $mod_sec;
         }
         $TIMEOUT = $num_sec;
         // IF PROGRESSIVE RATE
     } else {
         if ($this->debug_st) {
             echo "CYCLE A    TIMEOUT:{$TIMEOUT}\n";
         }
         // CYCLE A
         $credit -= $stepchargea;
         //if ($credit<=0) return "ERROR CT2"; //NO ENOUGH CREDIT TO CALL THIS NUMBER
         if ($credit <= 0) {
             if ($this->freetimetocall_left[$K] > 0) {
                 $this->ratecard_obj[$K]['timeout'] = $this->freetimetocall_left[$K];
                 if ($this->debug_st) {
                     print_r($this->ratecard_obj[$K]);
                 }
                 return $this->freetimetocall_left[$K];
             } else {
                 return "ERROR CT2";
                 //NO ENOUGH CREDIT TO CALL THIS NUMBER
             }
         }
         if (!($chargea > 0)) {
             return "ERROR CHARGEA({$chargea})";
         }
         $num_min = $credit / $chargea;
         if ($this->debug_st) {
             echo "            CYCLEA num_min:{$num_min} ({$credit}/{$chargea})\n";
         }
         $num_sec = intval($num_min * 60);
         if ($this->debug_st) {
             echo "            CYCLEA num_sec:{$num_sec} \n";
         }
         if ($billingblocka > 0) {
             $mod_sec = $num_sec % $billingblocka;
             $num_sec = $num_sec - $mod_sec;
         }
         if ($num_sec > $timechargea && !(empty($chargeb) || $chargeb == 0 || empty($timechargeb) || $timechargeb == 0)) {
             $TIMEOUT += $timechargea;
             $credit -= $chargea / 60 * $timechargea;
             if ($this->debug_st) {
                 echo "        CYCLE B        TIMEOUT:{$TIMEOUT}\n";
             }
             // CYCLE B
             $credit -= $stepchargeb;
             if ($credit <= 0) {
                 $this->ratecard_obj[$K]['timeout'] = $TIMEOUT + $this->freetimetocall_left[$K];
                 return $TIMEOUT + $this->freetimetocall_left[$K];
                 //NO ENOUGH CREDIT TO GO TO THE CYCLE B
             }
             if (!($chargeb > 0)) {
                 return "ERROR CHARGEB({$chargeb})";
             }
             $num_min = $credit / $chargeb;
             if ($this->debug_st) {
                 echo "            CYCLEB num_min:{$num_min} ({$credit}/{$chargeb})\n";
             }
             $num_sec = intval($num_min * 60);
             if ($this->debug_st) {
                 echo "            CYCLEB num_sec:{$num_sec} \n";
             }
             if ($billingblockb > 0) {
                 $mod_sec = $num_sec % $billingblockb;
                 $num_sec = $num_sec - $mod_sec;
             }
             if ($num_sec > $timechargeb && !(empty($chargec) || $chargec == 0 || empty($timechargec) || $timechargec == 0)) {
                 $TIMEOUT += $timechargeb;
                 $credit -= $chargeb / 60 * $timechargeb;
                 if ($this->debug_st) {
                     echo "                CYCLE C        TIMEOUT:{$TIMEOUT}\n";
                 }
                 // CYCLE C
                 $credit -= $stepchargec;
                 if ($credit <= 0) {
                     $this->ratecard_obj[$K]['timeout'] = $TIMEOUT + $this->freetimetocall_left[$K];
                     return $TIMEOUT + $this->freetimetocall_left[$K];
                     //NO ENOUGH CREDIT TO GO TO THE CYCLE C
                 }
                 if (!($chargec > 0)) {
                     return "ERROR CHARGEC({$chargec})";
                 }
                 $num_min = $credit / $chargec;
                 if ($this->debug_st) {
                     echo "            CYCLEC num_min:{$num_min} ({$credit}/{$chargec})\n";
                 }
                 $num_sec = intval($num_min * 60);
                 if ($this->debug_st) {
                     echo "            CYCLEC num_sec:{$num_sec} \n";
                 }
                 if ($billingblockc > 0) {
                     $mod_sec = $num_sec % $billingblockc;
                     $num_sec = $num_sec - $mod_sec;
                 }
                 if ($num_sec > $timechargec) {
                     if ($this->debug_st) {
                         echo "        OUT CYCLE C        TIMEOUT:{$TIMEOUT}\n";
                     }
                     $TIMEOUT += $timechargec;
                     $credit -= $chargec / 60 * $timechargec;
                     // IF CYCLE C IS FINISH USE THE RATEINITIAL
                     $num_min = $credit / $rateinitial;
                     if ($this->debug_st) {
                         echo "            OUT CYCLEC num_min:{$num_min} ({$credit}/{$rateinitial})\n";
                     }
                     $num_sec = intval($num_min * 60);
                     if ($this->debug_st) {
                         echo "            OUT CYCLEC num_sec:{$num_sec} \n";
                     }
                     if ($billingblock > 0) {
                         $mod_sec = $num_sec % $billingblock;
                         $num_sec = $num_sec - $mod_sec;
                     }
                     $TIMEOUT += $num_sec;
                     // THIS IS THE END
                 } else {
                     $TIMEOUT += $num_sec;
                 }
             } else {
                 if ($num_sec > $timechargeb) {
                     $TIMEOUT += $timechargeb;
                     if ($this->debug_st) {
                         echo "        OUT CYCLE B        TIMEOUT:{$TIMEOUT}\n";
                     }
                     $credit -= $chargeb / 60 * $timechargeb;
                     // IF CYCLE B IS FINISH USE THE RATEINITIAL
                     $num_min = $credit / $rateinitial;
                     if ($this->debug_st) {
                         echo "            OUT CYCLEB num_min:{$num_min} ({$credit}/{$rateinitial})\n";
                     }
                     $num_sec = intval($num_min * 60);
                     if ($this->debug_st) {
                         echo "            OUT CYCLEB num_sec:{$num_sec} \n";
                     }
                     if ($billingblock > 0) {
                         $mod_sec = $num_sec % $billingblock;
                         $num_sec = $num_sec - $mod_sec;
                     }
                     $TIMEOUT += $num_sec;
                     // THIS IS THE END
                 } else {
                     $TIMEOUT += $num_sec;
                 }
             }
         } else {
             if ($num_sec > $timechargea) {
                 $TIMEOUT += $timechargea;
                 if ($this->debug_st) {
                     echo "        OUT CYCLE A        TIMEOUT:{$TIMEOUT}\n";
                 }
                 $credit -= $chargea / 60 * $timechargea;
                 // IF CYCLE A IS FINISH USE THE RATEINITIAL
                 $num_min = $credit / $rateinitial;
                 if ($this->debug_st) {
                     echo "            OUT CYCLEA num_min:{$num_min} ({$credit}/{$rateinitial})\n";
                 }
                 $num_sec = intval($num_min * 60);
                 if ($this->debug_st) {
                     echo "            OUT CYCLEA num_sec:{$num_sec} \n";
                 }
                 if ($billingblock > 0) {
                     $mod_sec = $num_sec % $billingblock;
                     $num_sec = $num_sec - $mod_sec;
                 }
                 $TIMEOUT += $num_sec;
                 // THIS IS THE END
             } else {
                 $TIMEOUT += $num_sec;
             }
         }
     }
     //Call time to speak without rate rules... idiot rules
     $num_min_WR = $initial_credit / $rateinitial;
     $num_sec_WR = intval($num_min_WR * 60);
     $this->ratecard_obj[$K]['timeout_without_rules'] = $num_sec_WR + $this->freetimetocall_left[$K];
     $this->ratecard_obj[$K]['timeout'] = $TIMEOUT + $this->freetimetocall_left[$K];
     if ($this->debug_st) {
         print_r($this->ratecard_obj[$K]);
     }
     return $TIMEOUT + $this->freetimetocall_left[$K];
 }
Exemplo n.º 22
0
	/**
     * Function create_refill
     * @public
     */
	static public function create_refill_after_payment()
	{ 
		global $A2B;
		$FormHandler = FormHandler::GetInstance();
		$processed = $FormHandler->getProcessed();
		if ($processed['added_refill']==1) {
			$id_payment = $FormHandler -> RESULT_QUERY;
			// CREATE REFILL
			$field_insert = "date, credit, card_id ,refill_type, description";
			$date = $processed['date'];
			$credit = $processed['payment'];
			$card_id = $processed['card_id'];
			$refill_type= $processed['payment_type'];
			$description = $processed['description'];
            $card_table = new Table('cc_card','vat');
            $card_clause = "id = ".$card_id;
            $card_result = $card_table -> Get_list($FormHandler->DBHandle, $card_clause, 0);
            if(!is_array($card_result)||empty($card_result[0][0])||!is_numeric($card_result[0][0]))
            	$vat=0;
            else
            	$vat = $card_result[0][0];
            $credit_without_vat = $credit / (1+$vat/100);
            
			$value_insert = " '$date' , '$credit_without_vat', '$card_id','$refill_type', '$description' ";
			$instance_sub_table = new Table("cc_logrefill", $field_insert);
			$id_refill = $instance_sub_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");	
			// REFILL CARD .. UPADTE CARD
			$instance_table_card = new Table("cc_card");
			$param_update_card = "credit = credit + '".$credit_without_vat."'";
			$clause_update_card = " id='$card_id'";
			$instance_table_card -> Update_table ($FormHandler->DBHandle, $param_update_card, $clause_update_card, $func_table = null);
			//LINK THE REFILL TO THE PAYMENT .. UPADTE PAYMENT
			$instance_table_pay = new Table("cc_logpayment");
			$param_update_pay = "id_logrefill = '".$id_refill."'";
			$clause_update_pay = " id ='$id_payment'";
			$instance_table_pay-> Update_table ($FormHandler->DBHandle, $param_update_pay, $clause_update_pay, $func_table = null);
		
			// Create invoice associated
		
			// CREATE AND UPDATE REF NUMBER
			$list_refill_type=Constants::getRefillType_List();
			$refill_type = $processed['payment_type'];
			$year = date("Y");
			$invoice_conf_table = new Table('cc_invoice_conf','value');
			$conf_clause = "key_val = 'count_$year'";
			$result = $invoice_conf_table -> Get_list($FormHandler->DBHandle, $conf_clause, 0);
			if (is_array($result) && !empty($result[0][0])) {
				// update count
				$count =$result[0][0];
				if(!is_numeric($count)) $count=0;
				$count++;
				$param_update_conf = "value ='".$count."'";
				$clause_update_conf = "key_val = 'count_$year'";
				$invoice_conf_table -> Update_table ($FormHandler->DBHandle, $param_update_conf, $clause_update_conf, $func_table = null);
			} else {
				// insert newcount
				$count=1;
				$QUERY= "INSERT INTO cc_invoice_conf (key_val ,value) VALUES ( 'count_$year', '1');";
				$invoice_conf_table -> SQLExec($FormHandler->DBHandle,$QUERY);
			}
			$field_insert = "date, id_card, title ,reference, description,status,paid_status";
			if($refill_type!=0) {
				$title = $list_refill_type[$refill_type][0]." ".gettext("REFILL");
			} else {
				$title = gettext("REFILL");
			}
			$description = gettext("Invoice for refill");
			$reference = $year.sprintf("%08d",$count);
			$value_insert = " '$date' , '$card_id', '$title','$reference','$description','1','1' ";
			$instance_table = new Table("cc_invoice", $field_insert);
			$id_invoice = $instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
			//add payment to this invoice
			$field_insert = "id_invoice, id_payment";
			$value_insert = "'$id_invoice' , '$id_payment'";
			$instance_table = new Table("cc_invoice_payment", $field_insert);
			$instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null);
			//load vat of this card
			if (!empty($id_invoice) && is_numeric($id_invoice)) {
				$description = $processed['description'];
				$field_insert = "date, id_invoice ,price,vat, description";
				$instance_table = new Table("cc_invoice_item", $field_insert);
				$value_insert = " '$date' , '$id_invoice', '$credit_without_vat','$vat','$description' ";
				$instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
			}
		}
		
		if($processed['added_commission']==1) {
			$card_id = $processed['card_id'];
			$table_transaction = new Table();
			$result_agent = $table_transaction -> SQLExec($FormHandler->DBHandle,"SELECT cc_card_group.id_agent FROM cc_card LEFT JOIN cc_card_group ON cc_card_group.id = cc_card.id_group WHERE cc_card.id = $card_id");
			
			if (is_array($result_agent)&& !is_null($result_agent[0]['id_agent']) && $result_agent[0]['id_agent']>0 ) {
				
				// test if the agent exist and get its commission
				$id_agent = $result_agent[0]['id_agent'];
				// update refill & payment to keep a trace of agent in the timeline
				$table_refill = new Table("cc_logrefill");
				$table_payment = new Table("cc_logpayment");
				$param_update = "agent_id = '".$id_agent."'";
				if(!empty($id_refill)){
					$clause_update_refill_agent = " id ='$id_refill'";
					$table_refill-> Update_table ($FormHandler->DBHandle, $param_update, $clause_update_refill_agent, $func_table = null);
				}
				$clause_update_payment_agent = " id ='$id_payment'";
				$table_payment-> Update_table ($FormHandler->DBHandle, $param_update, $clause_update_payment_agent, $func_table = null);
				
				$agent_table = new Table("cc_agent", "commission");
				$agent_clause = "id = ".$id_agent;
				$result_agent= $agent_table -> Get_list($FormHandler->DBHandle,$agent_clause);
				
				if (is_array($result_agent) && is_numeric($result_agent[0]['commission']) && $result_agent[0]['commission']>0) {
					$field_insert = "id_payment, id_card, amount,description,id_agent";
					$commission = a2b_round($processed['payment'] * ($result_agent[0]['commission']/100));
					$description_commission = gettext("AUTOMATICALY GENERATED COMMISSION!");
					$description_commission.= "\nID CARD : ".$card_id;
					$description_commission.= "\nID PAYMENT : ".$id_payment;
					$description_commission.= "\nPAYMENT AMOUNT: ".$amount_paid;
					$description_commission.= "\nCOMMISSION APPLIED: ".$result_agent[0]['commission'];
					$value_insert = "'".$id_payment."', '$card_id', '$commission','$description_commission','$id_agent'";
					$commission_table = new Table("cc_agent_commission", $field_insert);
					$id_commission = $commission_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
					$table_agent = new Table('cc_agent');
					$param_update_agent = "com_balance = com_balance + '".$commission."'";
					$clause_update_agent = " id='".$id_agent."'";
					$table_agent -> Update_table ($FormHandler->DBHandle, $param_update_agent, $clause_update_agent, $func_table = null);
				}
			}	
		}
	}
Exemplo n.º 23
0
$QUERY = "SELECT cc.username, cc.credit, cc.status, cc.id, cc.id_didgroup, cc.tariff, cc.vat, ct.gmtoffset, cc.voicemail_permitted, " . "cc.voicemail_activated, cc_card_group.users_perms, cc.currency, cc_did.did " . "FROM cc_card cc " . "LEFT JOIN cc_timezone AS ct ON ct.id = cc.id_timezone LEFT JOIN cc_card_group ON cc_card_group.id=cc.id_group " . "LEFT JOIN cc_did ON cc_did.iduser=cc.id " . "LIMIT 0, {$Number_account}";
$res = $DBHandle->Execute($QUERY);
$num = $res->RecordCount();
if ($num == 0) {
    echo "Error : Fetching the account!";
    exit;
}
$Config_output = '';
for ($i = 0; $i < $num; $i++) {
    $accounts[$i] = $res->fetchRow();
    $card_id = $accounts[$i][3];
    $did = $accounts[$i][12];
    //$QUERY_IAX = "SELECT iax.id, iax.username, iax.secret, iax.disallow, iax.allow, iax.type, iax.host, iax.context FROM cc_iax_buddies iax WHERE iax.id_cc_card = $card_id";
    $QUERY_SIP = "SELECT sip.id, sip.username, sip.secret, sip.disallow, sip.allow, sip.type, sip.host, sip.context FROM cc_sip_buddies sip WHERE sip.id_cc_card = {$card_id}";
    //$iax_data = $table_instance->SQLExec ($DBHandle, $QUERY_IAX);
    $sip_data = $table_instance->SQLExec($DBHandle, $QUERY_SIP);
    //Additonal parameters
    $additional_sip = explode("|", SIP_ADDITIONAL_PARAMETERS);
    $additional_iax = explode("|", IAX_ADDITIONAL_PARAMETERS);
    // ADD REGISTER
    // register => [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry]
    // 2345:password@mysipprovider.com
    $Config_output .= "\n\n";
    $Config_output .= "; REGISTER COMMAND\n";
    $Config_output .= "register => " . $sip_data[0][1] . ":" . $sip_data[0][2] . "@{$Asterisk_IP}\n";
    // SIP
    $Config_output .= "\nDID : {$did}\n";
    $Config_output .= "[{$trunkname}]\n";
    $Config_output .= "username="******"\n";
    $Config_output .= "type=friend\n";
    $Config_output .= "secret=" . $sip_data[0][2] . "\n";
Exemplo n.º 24
0
			</table>
			</td>
		</tr>


		<tr>
			<td width="19%" align="left" valign="top" class="bgcolor_004">					
				<font class="fontstyle_003">&nbsp;&nbsp;<?php echo gettext("SELECT GROUP");?></font>
			</td>				
			<td width="81%" align="left" class="bgcolor_005">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
			  <td class="fontstyle_searchoptions">
			  <?php
				$instance_table = new Table();
				$QUERY = "SELECT * from cc_config_group"; 					
				$list_total_groups  = $instance_table->SQLExec ($HD_Form -> DBHandle, $QUERY);		
			   ?>
			<select name="groupselect" class="form_input_select">
			<option value="-1" ><?php echo gettext("Select Group");?></option>
			<?php 
			foreach($list_total_groups as $groupname){
			?>
			<option value="<?php echo $groupname[1]?>" <?php if($groupselect == $groupname[1] || $groupname[1] == $_SESSION['grpselect']) echo "selected"?>><?php echo $groupname[1]?></option>
			<?php 
			}
			?>
			</select>
				</td>					
			</tr></table></td>
		</tr>			
	
 /**
  * Function to execture the appropriate action
  * @public     	 
  */
 function perform_action(&$form_action)
 {
     //security check
     switch ($form_action) {
         case "ask-add":
         case "add":
             if (!$this->FG_ADDITION) {
                 Header("Location: " . $_SERVER['PHP_SELF']);
                 die;
             }
             break;
         case "ask-edit":
         case "edit":
             if (!$this->FG_EDITION) {
                 Header("Location: " . $_SERVER['PHP_SELF']);
                 die;
             }
             break;
         case "ask-del-confirm":
         case "ask-delete":
         case "delete":
             if (!$this->FG_DELETION) {
                 Header("Location: " . $_SERVER['PHP_SELF']);
                 die;
             }
             break;
     }
     switch ($form_action) {
         case "add":
             $this->perform_add($form_action);
             break;
         case "edit":
             $this->perform_edit($form_action);
             break;
         case "delete":
             $this->perform_delete($form_action);
             break;
     }
     $processed = $this->getProcessed();
     //$processed['firstname']
     if ($form_action == "ask-delete" && in_array($processed['id'], $this->FG_DELETION_FORBIDDEN_ID)) {
         if (!empty($this->FG_GO_LINK_AFTER_ACTION_DELETE)) {
             Header("Location: " . $this->FG_GO_LINK_AFTER_ACTION_DELETE . $processed['id']);
         } else {
             Header("Location: " . $_SERVER['PHP_SELF']);
         }
         die;
     }
     if ($form_action == "list" || $form_action == "edit" || $form_action == "ask-delete" || $form_action == "ask-edit" || $form_action == "add-content" || $form_action == "del-content" || $form_action == "ask-del-confirm") {
         include_once FSROOT . "lib/Class.Table.php";
         $this->FG_ORDER = $processed['order'];
         $this->FG_SENS = $processed['sens'];
         $this->CV_CURRENT_PAGE = $processed['current_page'];
         $session_limit = $this->FG_TABLE_NAME . "-displaylimit";
         if (isset($_SESSION[$session_limit]) && is_numeric($_SESSION[$session_limit])) {
             $this->FG_LIMITE_DISPLAY = $_SESSION[$session_limit];
         }
         if (isset($processed['mydisplaylimit']) && (is_numeric($processed['mydisplaylimit']) || $processed['mydisplaylimit'] == 'ALL')) {
             if ($processed['mydisplaylimit'] == 'ALL') {
                 $this->FG_LIMITE_DISPLAY = 5000;
             } else {
                 $this->FG_LIMITE_DISPLAY = $processed['mydisplaylimit'];
             }
             $_SESSION[$this->FG_TABLE_NAME . "-displaylimit"] = $this->FG_LIMITE_DISPLAY;
         }
         if ($this->FG_ORDER == "" || $this->FG_SENS == "") {
             $this->FG_ORDER = $this->FG_TABLE_DEFAULT_ORDER;
             $this->FG_SENS = $this->FG_TABLE_DEFAULT_SENS;
         }
         if ($form_action == "list") {
             $sql_calc_found_rows = '';
             if (DB_TYPE != "postgres") {
                 $sql_calc_found_rows = 'SQL_CALC_FOUND_ROWS';
             }
             $instance_table = new Table($this->FG_TABLE_NAME, "{$sql_calc_found_rows} " . $this->FG_COL_QUERY, null, null, null, true, $this->FG_TABLE_NAME_COUNT);
             $this->prepare_list_subselection($form_action);
             // Code here to call the Delete Selected items Fucntion
             if (isset($processed['deleteselected'])) {
                 $this->Delete_Selected();
             }
             if ($this->FG_DEBUG >= 2) {
                 echo "FG_CLAUSE:{$this->FG_CLAUSE}";
                 echo "FG_ORDER = " . $this->FG_ORDER . "<br>";
                 echo "FG_SENS = " . $this->FG_SENS . "<br>";
                 echo "FG_LIMITE_DISPLAY = " . $this->FG_LIMITE_DISPLAY . "<br>";
                 echo "CV_CURRENT_PAGE = " . $this->CV_CURRENT_PAGE . "<br>";
             }
             $list = $instance_table->Get_list($this->DBHandle, $this->FG_TABLE_CLAUSE, $this->FG_ORDER, $this->FG_SENS, null, null, $this->FG_LIMITE_DISPLAY, $this->CV_CURRENT_PAGE * $this->FG_LIMITE_DISPLAY, $this->SQL_GROUP);
             if ($this->FG_DEBUG == 3) {
                 echo "<br>Clause : " . $this->FG_TABLE_CLAUSE;
             }
             if (DB_TYPE == "postgres") {
                 $this->FG_NB_RECORD = $instance_table->Table_count($this->DBHandle, $this->FG_TABLE_CLAUSE);
             } else {
                 $res_count = $instance_table->SQLExec($this->DBHandle, "SELECT FOUND_ROWS() as count", 1);
                 $this->FG_NB_RECORD = $res_count[0][0];
             }
             if ($this->FG_DEBUG >= 1) {
                 var_dump($list);
             }
             if ($this->FG_NB_RECORD <= $this->FG_LIMITE_DISPLAY) {
                 $this->FG_NB_RECORD_MAX = 1;
             } else {
                 $this->FG_NB_RECORD_MAX = ceil($this->FG_NB_RECORD / $this->FG_LIMITE_DISPLAY);
             }
             if ($this->FG_DEBUG == 3) {
                 echo "<br>Nb_record : " . $this->FG_NB_RECORD;
             }
             if ($this->FG_DEBUG == 3) {
                 echo "<br>Nb_record_max : " . $this->FG_NB_RECORD_MAX;
             }
         } else {
             $instance_table = new Table($this->FG_TABLE_NAME, $this->FG_QUERY_EDITION);
             $list = $instance_table->Get_list($this->DBHandle, $this->FG_EDITION_CLAUSE, null, null, null, null, 1, 0);
             //PATCH TO CLEAN THE IMPORT OF PASSWORD FROM THE DATABASE
             if (substr_count($this->FG_QUERY_EDITION, "pwd_encoded") > 0) {
                 $tab_field = explode(',', $this->FG_QUERY_EDITION);
                 for ($i = 0; $i < count($tab_field); $i++) {
                     if (trim($tab_field[$i]) == "pwd_encoded") {
                         $list[0][$i] = "";
                     }
                 }
             }
             if (isset($list[0]["pwd_encoded"])) {
                 $list[0]["pwd_encoded"] = "";
             }
         }
         if ($this->FG_DEBUG >= 2) {
             print_r($list);
         }
     }
     return $list;
 }
Exemplo n.º 26
0
            if ($view_type == "month") {
                $QUERY = "SELECT UNIX_TIMESTAMP( DATE_FORMAT( date, '%Y-%m-01' ) )*1000 AS this_month, count( * )  FROM cc_logpayment WHERE date >= TIMESTAMP( '{$checkdate_month}' ) AND date <=CURRENT_TIMESTAMP GROUP BY this_month ORDER BY this_month;";
            } else {
                $QUERY = "SELECT UNIX_TIMESTAMP( DATE_FORMAT( date, '%Y-%m-%d' ) )*1000 AS this_day, count( * )  FROM cc_logpayment WHERE date >= TIMESTAMP( '{$checkdate_day}' ) AND date <=CURRENT_TIMESTAMP GROUP BY this_day ORDER BY this_day;";
            }
            break;
        case 'payments_amount':
            if ($view_type == "month") {
                $QUERY = "SELECT UNIX_TIMESTAMP( DATE_FORMAT( date, '%Y-%m-01' ) )*1000 AS this_month , SUM( payment )  FROM cc_logpayment WHERE date >= TIMESTAMP( '{$checkdate_month}' ) AND date <=CURRENT_TIMESTAMP GROUP BY this_month ORDER BY this_month;";
            } else {
                $QUERY = "SELECT UNIX_TIMESTAMP( DATE_FORMAT( date, '%Y-%m-%d' ) )*1000 AS this_day , SUM( payment )  FROM cc_logpayment WHERE date >= TIMESTAMP( '{$checkdate_day}' ) AND date <=CURRENT_TIMESTAMP GROUP BY this_day ORDER BY this_day;";
            }
            $format = 'money';
            break;
    }
    $result_graph = $table->SQLExec($DBHandle, $QUERY);
    $max = 0;
    $data = array();
    if (is_array($result_graph)) {
        for ($i = 0; $i < count($result_graph); $i++) {
            $max = max($max, $result_graph[$i][1]);
            $data[] = array($result_graph[$i][0], floatval($result_graph[$i][1]));
        }
    }
    $response = array('max' => floatval($max), 'data' => $data, 'format' => $format);
    if ($DEBUG_MODULE) {
        $response['query'] = $QUERY;
    }
    echo json_encode($response);
    die;
}
             echo "INSERT INVOICE ITEM : {$field_insert} =>\t{$value_insert} \n";
         }
         $instance_table->Add_table($A2B->DBHandle, $value_insert, null, null, "id");
     }
     $mail = new Mail(Mail::$TYPE_SUBSCRIPTION_UNPAID, $card['id']);
     $mail->replaceInEmail(Mail::$DAY_REMAINING_KEY, $billdaybefor_anniversary);
     $mail->replaceInEmail(Mail::$INVOICE_REF_KEY, $reference);
     $mail->replaceInEmail(Mail::$SUBSCRIPTION_FEE, $subscription['fee']);
     $mail->replaceInEmail(Mail::$SUBSCRIPTION_ID, $subscription['id']);
     $mail->replaceInEmail(Mail::$SUBSCRIPTION_LABEL, $subscription['product_name']);
     //insert charge
     $QUERY = "INSERT INTO cc_charge (id_cc_card, amount, chargetype, id_cc_card_subscription, invoiced_status, description) VALUES ('" . $card['id'] . "', '" . $subscription['fee'] . "', '3','" . $subscription['card_subscription_id'] . "',1, '" . $subscription['product_name'] . "')";
     if ($verbose_level >= 1) {
         echo "==> INSERT CHARGE QUERY: \t{$QUERY}\n";
     }
     $instance_table->SQLExec($A2B->DBHandle, $QUERY, 0);
     $QUERY = "UPDATE cc_card_subscription SET paid_status = 1 WHERE id=" . $subscription['card_subscription_id'];
     if ($verbose_level >= 1) {
         echo "==> UPDATE SUBSCRIPTION QUERY : {$QUERY}\n";
     }
     $result = $instance_table->SQLExec($A2B->DBHandle, $QUERY, 0);
     try {
         $mail->send();
     } catch (A2bMailException $e) {
         if ($verbose_level >= 1) {
             echo "[Sent mail failed : {$e}]";
         }
         write_log(LOGFILE_CRONT_SUBSCRIPTIONFEE, basename(__FILE__) . ' line:' . __LINE__ . "[Sent mail failed : {$e}]");
     }
 }
 $QUERY = "UPDATE cc_card_subscription SET last_run = '{$last_run}', next_billing_date = '{$next_bill_date}', limit_pay_date = '{$limite_pay_date}' WHERE id=" . $subscription['card_subscription_id'];
Exemplo n.º 28
0
 if ($search_sources != 'nochange') {
     $fieldtomerge = preg_split("/\t/", $search_sources);
     $fieldtomerge_sql = str_replace("\t", ", ", $search_sources);
     $fieldtomerge_sql = trim($fieldtomerge_sql);
     //if (strlen($fieldtomerge_sql)>0) $fieldtomerge_sql = ', '.$fieldtomerge_sql;
 }
 if (!$bool) {
     $count = 0;
     $fields = "dialprefix, ";
     $fields .= $fieldtomerge_sql;
     $fields_array = preg_split('/,/', $fields);
     if (!empty($_SESSION['search_ratecard'])) {
         $condition .= " AND " . $_SESSION['search_ratecard'];
     }
     $sql = "select {$fields} from cc_ratecard where idtariffplan = {$ratecard_src_val} {$condition} order by dialprefix,id";
     $result = $instance_table->SQLExec($HD_Form->DBHandle, $sql);
     $q = "";
     $q_update = "";
     for ($i = 0; $i < count($result); $i++) {
         $Update = "";
         for ($k = 0; $k < count($fields_array); $k++) {
             $val = $result[$i][$k];
             if ($k == 0) {
                 $dialprefix = $result[$i][$k];
             } else {
                 $Update .= ",";
             }
             $Update .= "{$fields_array[$k]} = '{$val}'";
         }
         $replac_able = "dialprefix = '" . $dialprefix . "',";
         $Update = str_replace($replac_able, "", $Update);
Exemplo n.º 29
0
if (!has_rights(ACX_DASHBOARD)) {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
$DBHandle = DbConnect();
$QUERY_COUNT_CARD_ALL = "SELECT count(*) FROM cc_card";
$QUERY_COUNT_CARD_ACTIVED = "SELECT count(*) FROM cc_card WHERE status = 1";
$QUERY_COUNT_CARD_CANCELLED = "SELECT count(*) FROM cc_card WHERE status = 0";
$QUERY_COUNT_CARD_NEW = "SELECT count(*) FROM cc_card WHERE status = 2";
$QUERY_COUNT_CARD_WAITING = "SELECT count(*) FROM cc_card WHERE status = 3";
$QUERY_COUNT_CARD_RESERVED = "SELECT count(*) FROM cc_card WHERE status = 4";
$QUERY_COUNT_CARD_EXPIRED = "SELECT count(*) FROM cc_card WHERE status = 5";
$QUERY_COUNT_CARD_SUSPENDED = "SELECT count(*) FROM cc_card WHERE status = 6 OR status = 7";
$table = new Table('cc_card', '*');
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_ALL);
$result_count_all = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_ACTIVED);
$result_count_actived = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_CANCELLED);
$result_count_cancelled = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_NEW);
$result_count_new = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_WAITING);
$result_count_waiting = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_RESERVED);
$result_count_reserved = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_EXPIRED);
$result_count_expired = $result[0][0];
$result = $table->SQLExec($DBHandle, $QUERY_COUNT_CARD_SUSPENDED);
$result_count_suspended = $result[0][0];
Exemplo n.º 30
0
    $description = gettext("Automated Refill : recurring payment");
    $field_insert = "date, id_invoice ,price,vat, description";
    $instance_table = new Table("cc_invoice_item", $field_insert);
    $value_insert = " '{$date}' , '{$id_invoice}', '{$amount}','{$VAT}','{$description}' ";
    $instance_table->Add_table($DBHandle, $value_insert, null, null, "id");
}
//link payment to this invoice
$table_payment_invoice = new Table("cc_invoice_payment", "*");
$fields = " id_invoice , id_payment";
$values = " {$id_invoice}, {$id_payment}\t";
$table_payment_invoice->Add_table($DBHandle, $values, $fields);
//END INVOICE
//Agent commision
// test if this card have a agent
$table_transaction = new Table();
$result_agent = $table_transaction->SQLExec($DBHandle, "SELECT cc_card_group.id_agent FROM cc_card LEFT JOIN cc_card_group ON cc_card_group.id = cc_card.id_group WHERE cc_card.id = {$id}");
if (is_array($result_agent) && !is_null($result_agent[0]['id_agent']) && $result_agent[0]['id_agent'] > 0) {
    //test if the agent exist and get its commission
    $id_agent = $result_agent[0]['id_agent'];
    $agent_table = new Table("cc_agent", "commission");
    $agent_clause = "id = " . $id_agent;
    $result_agent = $agent_table->Get_list($DBHandle, $agent_clause);
    if (is_array($result_agent) && is_numeric($result_agent[0]['commission']) && $result_agent[0]['commission'] > 0) {
        $field_insert = "id_payment, id_card, amount,description,id_agent";
        $commission = ceil($amount_paid * $result_agent[0]['commission'] / 100 * 100) / 100;
        $description_commission = gettext("AUTOMATICALY GENERATED COMMISSION!");
        $description_commission .= "\nID CARD : " . $id;
        $description_commission .= "\nID PAYMENT : " . $id_payment;
        $description_commission .= "\nPAYMENT AMOUNT: " . $amount_paid;
        $description_commission .= "\nCOMMISSION APPLIED: " . $result_agent[0]['commission'];
        $value_insert = "'" . $id_payment . "', '{$id}', '{$commission}','{$description_commission}','{$id_agent}'";