From Ungracious Agouti, 3 Years ago, written in PHP.
- go back
Embed
Viewing differences between and astpp.apfax.php
  1. <?php
  2. // ##############################################################################
  3. // ASTPP - Open Source VoIP Billing Solution
  4. //
  5. // Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
  6. // Samir Doshi <samir.doshi@inextrix.com>
  7. // ASTPP Version 3.0 and above
  8. // License https://www.gnu.org/licenses/agpl-3.0.html
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU Affero General Public License as
  12. // published by the Free Software Foundation, either version 3 of the
  13. // License, or (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU Affero General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Affero General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. // ##############################################################################
  23.  
  24. function custom_process_hook_6($actual_calltype,$dataVariable,$accountid,$check_type,$logger,$db){
  25.         $fax_array = array();
  26.         $logger->log("actual_calltype: " . $actual_calltype);
  27.         if((isset($actual_calltype) && $actual_calltype == "FAX") || (isset($dataVariable['fax_success']) && $dataVariable['fax_success'] != '')){
  28.            $parentid = isset ( $dataVariable ['parent_id'] ) ? $dataVariable ['parent_id'] : '0';
  29.            $callerIdNumber = ($dataVariable ['calltype'] == "DID") ? $dataVariable ['effective_caller_id_name'] . " <" . $dataVariable ['effective_caller_id_number'] . ">" : $dataVariable ['original_caller_id_name'] . " <" . $dataVariable ['original_caller_id_number'] . ">";
  30.            $file_name = $dataVariable ['fax_file_name_custom'];//$dataVariable ['uuid']."-FAX.pdf";
  31.            $uuid = $dataVariable ['uuid'];
  32.            $destination_number = $dataVariable ['effective_destination_number'];
  33.            $date = gmdate('Y-m-d H:i:s');
  34.            if(isset($dataVariable['sip_h_P-fax_id'])){
  35.                 $query = "SELECT value FROM system WHERE name='folder_path'";
  36.                 $logger->log ( "GET configuration  : " . $query );
  37.                 $system = $db->run ( $query );
  38.                 $system_path = $system[0]['value'];
  39.                 $logger->log('System Path:::'.$system_path);
  40.                 $accountcode = $dataVariable['sip_h_P-Accountcode'];
  41.                
  42.                 $query = "SELECT id FROM accounts WHERE number='$accountcode'";
  43.                 $logger->log ( "GET configuration  : " . $query );
  44.                 $account = $db->run ( $query );
  45.                 $accountid = (isset($account) and $account[0]['id'] != '')?$account[0]['id']:$accountcode;
  46.                
  47.                 $logger->log('FAX accountid:::'.$accountid);
  48.                 $caller_id = $dataVariable ['effective_caller_id_number'];
  49.                 if($caller_id == ''){
  50.                         $caller_id = $dataVariable ['sip_h_P-e_number'];
  51.                 }
  52.                                 $logger->log("Fax caller ID : " . $caller_id);
  53.                 if(isset($dataVariable['fax_success']) && $dataVariable['fax_success'] == "0"){
  54.                         $logger->log("sip_h_P-fax_count : " . $dataVariable['sip_h_P-fax_count']);
  55.                         $logger->log("sip_h_P-retries_count : " . $dataVariable['sip_h_P-retries_count']);
  56.                         if($dataVariable['sip_h_P-fax_count'] < $dataVariable['sip_h_P-retries_count']){
  57.                                 $query = "update tbl_fax set is_sent = 3, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
  58.                                 $logger->log("tbl_fax update : " . $query);
  59.                                 $db->run($query);
  60.                                 return true;
  61.                         }
  62.                         if(!isset($dataVariable['fax_document_total_pages']) || $dataVariable['fax_document_total_pages'] == ''){
  63.                                 $dataVariable['fax_document_total_pages'] =0;
  64.                         }
  65.                         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);
  66.                 $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);
  67.  
  68.                         $dataVariable['hangup_cause']  = 'ALLOTTED_TIMEOUT';
  69.                 }
  70.                 $logger->log("Fax123465789 fail ".$dataVariable['fax_success']);
  71.                 if(!isset($dataVariable['fax_success'])){
  72.                         if($dataVariable['sip_h_P-fax_count'] < $dataVariable['sip_h_P-retries_count']){
  73.                                 $query = "update tbl_fax set is_sent = 3, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
  74.                                 $logger->log("tbl_fax update : " . $query);
  75.                                 $db->run($query);
  76.                                 return true;
  77.                         }
  78.                         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);
  79.                         $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);
  80.  
  81.                         $dataVariable['hangup_cause']  == 'ALLOTTED_TIMEOUT';
  82.                 }
  83.                 if($dataVariable['fax_success'] && $dataVariable['fax_success'] == "1"){
  84.                         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);
  85.                         $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);
  86.                         $query = "update tbl_fax set is_sent = 1, fax_status=0 where id=".$dataVariable['sip_h_P-fax_id'];
  87.                         $logger->log("tbl_fax update : " . $query);
  88.                         $db->run($query);
  89.                         $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')";
  90.                         $logger->log("tbl_fax insert query : " . $fax_query);
  91.                         $db->run($fax_query);
  92.                 }
  93.            }else{
  94.                 if($dataVariable['fax_success'] && $dataVariable['fax_success'] == "1"){
  95.                         $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')";
  96.                         $logger->log("tbl_fax insert query : " . $fax_query);
  97.                         $db->run($fax_query);
  98.                 }else{
  99.                         return true;
  100.                 }
  101.  
  102.            }
  103.                 $fax_array = array('accountid'=>$accountid);
  104.         }
  105.                 return $fax_array;
  106. }
  107.  
  108. ?>
  109.