<?php
// ##############################################################################
// ASTPP - Open Source VoIP Billing Solution
//
// Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
// Samir Doshi <samir.doshi@inextrix.com>
// ASTPP Version 3.0 and above
// License https://www.gnu.org/licenses/agpl-3.0.html
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ##############################################################################
function custom_process_hook_6($actual_calltype,$dataVariable,$accountid,$check_type,$logger,$db){
$logger->log("actual_calltype: " . $actual_calltype);
if((isset($actual_calltype) && $actual_calltype == "FAX") || (isset($dataVariable['fax_success']) && $dataVariable['fax_success'] != '')){
$parentid = isset ( $dataVariable ['parent_id'] ) ?
$dataVariable ['parent_id'] : '0';
$callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name'] . " <" . $dataVariable ['effective_caller_id_number'] . ">" : $dataVariable ['original_caller_id_name'] . " <" . $dataVariable ['original_caller_id_number'] . ">";
$file_name = $dataVariable ['fax_file_name_custom'];//$dataVariable ['uuid']."-FAX.pdf";
$uuid = $dataVariable ['uuid'];
$destination_number = $dataVariable ['effective_destination_number'];
$date = gmdate('Y-m-d H:i:s');
if(isset($dataVariable['sip_h_P-fax_id'])){
$query = "SELECT value FROM system WHERE name='folder_path'";
$logger->log ( "GET configuration : " . $query );
$system = $db->run ( $query );
$system_path = $system[0]['value'];
$logger->log('System Path:::'.$system_path);
$accountcode = $dataVariable['sip_h_P-Accountcode'];
$query = "SELECT id FROM accounts WHERE number='$accountcode'";
$logger->log ( "GET configuration : " . $query );
$account = $db->run ( $query );
$accountid = (isset($account) and
$account[0]['id'] != '')?
$account[0]['id']:$accountcode;
$logger->log('FAX accountid:::'.$accountid);
$caller_id = $dataVariable ['effective_caller_id_number'];
if($caller_id == ''){
$caller_id = $dataVariable ['sip_h_P-e_number'];
}
$logger->log("Fax caller ID : " . $caller_id);
if(isset($dataVariable['fax_success']) && $dataVariable['fax_success'] == "0"){
$logger->log("sip_h_P-fax_count : " . $dataVariable['sip_h_P-fax_count']);
$logger->log("sip_h_P-retries_count : " . $dataVariable['sip_h_P-retries_count']);
if($dataVariable['sip_h_P-fax_count'] < $dataVariable['sip_h_P-retries_count']){
$query = "update tbl_fax set is_sent = 3, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
$logger->log("tbl_fax update : " . $query);
$db->run($query);
return true;
}
if(!isset($dataVariable['fax_document_total_pages']) || $dataVariable['fax_document_total_pages'] == ''){
$dataVariable['fax_document_total_pages'] =0;
}
exec('php '.$system_path.'FAX/scripts/sendfax_status.php fail '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$logger->log('Fax fail1 php '.$system_path.'FAX/scripts/sendfax_status.php fail '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$dataVariable['hangup_cause'] = 'ALLOTTED_TIMEOUT';
}
$logger->log("Fax123465789 fail ".$dataVariable['fax_success']);
if(!isset($dataVariable['fax_success'])){
if($dataVariable['sip_h_P-fax_count'] < $dataVariable['sip_h_P-retries_count']){
$query = "update tbl_fax set is_sent = 3, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
$logger->log("tbl_fax update : " . $query);
$db->run($query);
return true;
}
exec('php '.$system_path.'FAX/scripts/sendfax_status.php fail '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$logger->log('Fax fail2 php '.$system_path.'FAX/scripts/sendfax_status.php fail '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$dataVariable['hangup_cause'] == 'ALLOTTED_TIMEOUT';
}
if($dataVariable['fax_success'] && $dataVariable['fax_success'] == "1"){
exec('php '.$system_path.'FAX/scripts/sendfax_status.php sucess '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$logger->log('Fax sucess php '.$system_path.'FAX/scripts/sendfax_status.php sucess '.$accountid.' '.$dataVariable['effective_destination_number'].' '.$dataVariable['fax_document_total_pages']. ' '. $dataVariable['billsec'].' '.$dataVariable['sip_h_P-fax_id'].' '.$caller_id);
$query = "update tbl_fax set is_sent = 1, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
$logger->log("tbl_fax update : " . $query);
$db->run($query);
$fax_query = "insert into tbl_fax(`fax_status`,`uniqueid`,`accountid`,`reseller_id`,`sip_device`,`number`,`type`,`file_name`,`sender`,`reciever`,`fax_title`,`pricelist_id`,`outbound_rate`,`origination_rate`,`created_date`,`is_sent`,`count`,`status`,`fax_sent`) VALUES('1','$uuid','$accountid','$parentid','$callerIdNumber','$destination_number','1','$file_name','','$destination_number','FAX SEND SUCCESSFULLY','0','','','$date','1','0','Send','2')";
$logger->log("tbl_fax insert query : " . $fax_query);
$db->run($fax_query);
}
}else{
if($dataVariable['fax_success'] && $dataVariable['fax_success'] == "1"){
$fax_query = "insert into tbl_fax(`fax_status`,`uniqueid`,`accountid`,`reseller_id`,`sip_device`,`number`,`type`,`file_name`,`sender`,`reciever`,`fax_title`,`pricelist_id`,`outbound_rate`,`origination_rate`,`created_date`,`is_sent`,`count`,`status`,`fax_sent`) VALUES('1','$uuid','$accountid','$parentid','$callerIdNumber','$destination_number','1','$file_name','','$destination_number','FAX SEND SUCCESSFULLY','0','','','$date','1','0','Send','2')";
$logger->log("tbl_fax insert query : " . $fax_query);
$db->run($fax_query);
}else{
return true;
}
}
$fax_array = array('accountid'=>$accountid);
}
return $fax_array;
}
?>