@@ -40,11 +40,11 @@ class CalcAgi
4040 public $ sessionbill = 0 ;
4141 public $ sipiax = 0 ;
4242 public $ id_campaign = '' ;
43- public $ tariffObj = array () ;
44- public $ freetimetocall_left = array () ;
45- public $ freecall = array () ;
46- public $ offerToApply = array () ;
47- public $ didAgi = array () ;
43+ public $ tariffObj = [] ;
44+ public $ freetimetocall_left = [] ;
45+ public $ freecall = [] ;
46+ public $ offerToApply = [] ;
47+ public $ didAgi = [] ;
4848 public $ dialstatus_rev_list ;
4949 public $ id_prefix ;
5050 public $ id_provider ;
@@ -67,7 +67,7 @@ public function init()
6767
6868 public function calculateAllTimeout (&$ MAGNUS , $ agi )
6969 {
70- if (! is_array ($ this ->tariffObj ) || count ($ this ->tariffObj ) == 0 ) {
70+ if ( ! is_array ($ this ->tariffObj ) || count ($ this ->tariffObj ) == 0 ) {
7171 return false ;
7272 }
7373
@@ -115,14 +115,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
115115 $ agi ->verbose ("offer Unlimited calls " );
116116 $ this ->freecall [0 ] = true ;
117117 $ package_selected = true ;
118- $ this ->offerToApply [0 ] = array (
118+ $ this ->offerToApply [0 ] = [
119119 "id " => $ id_offer ,
120120 "label " => "Unlimited calls " ,
121121 "type " => $ packagetype ,
122122 "billingblock " => $ modelOffer ->billingblock ,
123123 "initblock " => $ modelOffer ->initblock ,
124124 "minimal_time_charge " => $ modelOffer ->minimal_time_charge ,
125- ) ;
125+ ] ;
126126 break ;
127127 case 1 :
128128
@@ -133,14 +133,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
133133 if ($ number_calls_used < $ freetimetocall ) {
134134 $ this ->freecall [0 ] = true ;
135135 $ package_selected = true ;
136- $ this ->offerToApply [0 ] = array (
136+ $ this ->offerToApply [0 ] = [
137137 "id " => $ id_offer ,
138138 "label " => "Number of Free calls " ,
139139 "type " => $ packagetype ,
140140 "billingblock " => $ modelOffer ->billingblock ,
141141 "initblock " => $ modelOffer ->initblock ,
142142 "minimal_time_charge " => $ modelOffer ->minimal_time_charge ,
143- ) ;
143+ ] ;
144144 $ agi ->verbose (print_r ($ this ->offerToApply [0 ], true ), 6 );
145145 }
146146 }
@@ -156,14 +156,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
156156
157157 if ($ this ->freetimetocall_left [0 ] > 0 ) {
158158 $ package_selected = true ;
159- $ this ->offerToApply [0 ] = array (
159+ $ this ->offerToApply [0 ] = [
160160 "id " => $ id_offer ,
161161 "label " => "Free minutes " ,
162162 "type " => $ packagetype ,
163163 "billingblock " => $ modelOffer ->billingblock ,
164164 "initblock " => $ modelOffer ->initblock ,
165165 "minimal_time_charge " => $ modelOffer ->minimal_time_charge ,
166- ) ;
166+ ] ;
167167 $ agi ->verbose (print_r ($ this ->offerToApply [0 ], true ), 6 );
168168 }
169169 }
@@ -174,34 +174,30 @@ public function calculateTimeout(&$MAGNUS, $agi)
174174
175175 $ credit -= $ connectcharge ;
176176 $ this ->tariffObj [0 ]['timeout ' ] = 0 ;
177- $ this ->tariffObj [0 ]['timeout_without_rules ' ] = 0 ;
178177 $ this ->tariffObj [0 ]['freetime_include_in_timeout ' ] = $ this ->freetimetocall_left [0 ];
179178 $ agi ->verbose ("Credit $ credit " , 20 );
180- if ($ credit < 0 && !$ this ->freecall [0 ] && $ this ->freetimetocall_left [0 ] <= 0 ) {
179+ if ($ credit < 0 && ! $ this ->freecall [0 ] && $ this ->freetimetocall_left [0 ] <= 0 ) {
181180 return "ERROR CT1 " ;
182181 /*NO CREDIT TO CALL */
183182 }
184183
185184 $ TIMEOUT = 0 ;
186185 $ answeredtime_1st_leg = 0 ;
187- if ($ rateinitial <= 0 ) /*Se o preço for 0, entao retornar o timeout em 3600 s*/ {
188- $ this ->tariffObj [0 ]['timeout ' ] = 3600 ;
189- $ this ->tariffObj [0 ]['timeout_without_rules ' ] = 3600 ;
190- $ TIMEOUT = 3600 ;
186+ if ($ rateinitial <= 0 ) /*Se o preço for 0, entao retornar o timeout em 3600 s*/ {
187+ $ this ->tariffObj [0 ]['timeout ' ] = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
188+ $ TIMEOUT = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
191189 return $ TIMEOUT ;
192190 }
193191
194- if ($ this ->freecall [0 ]) /*usado para planos gratis*/ {
195- $ this ->tariffObj [0 ]['timeout ' ] = 3600 ;
196- $ TIMEOUT = 3600 ;
197- $ this ->tariffObj [0 ]['timeout_without_rules ' ] = 3600 ;
198- $ this ->tariffObj [0 ]['freetime_include_in_timeout ' ] = 3600 ;
192+ if ($ this ->freecall [0 ]) /*usado para planos gratis*/ {
193+ $ this ->tariffObj [0 ]['timeout ' ] = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
194+ $ TIMEOUT = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
195+ $ this ->tariffObj [0 ]['freetime_include_in_timeout ' ] = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
199196 return $ TIMEOUT ;
200197 }
201198 if ($ credit < 0 && $ this ->freetimetocall_left [0 ] > 0 ) {
202- $ this ->tariffObj [0 ]['timeout ' ] = $ this ->freetimetocall_left [0 ];
203- $ TIMEOUT = $ this ->freetimetocall_left [0 ];
204- $ this ->tariffObj [0 ]['timeout_without_rules ' ] = $ this ->freetimetocall_left [0 ];
199+ $ this ->tariffObj [0 ]['timeout ' ] = $ this ->freetimetocall_left [0 ];
200+ $ TIMEOUT = $ this ->freetimetocall_left [0 ];
205201 return $ TIMEOUT ;
206202 }
207203
@@ -215,19 +211,21 @@ public function calculateTimeout(&$MAGNUS, $agi)
215211 }
216212
217213 $ num_sec = intval ($ num_min * 60 ) - $ answeredtime_1st_leg ; /*numero de segundos - o tempo que gastou para completar*/
214+
218215 if ($ billingblock > 0 ) {
219216 $ mod_sec = $ num_sec % $ billingblock ;
220217 $ num_sec = $ num_sec - $ mod_sec ;
221218 }
222219 $ TIMEOUT = $ num_sec ;
223220
224221 /*Call time to speak without rate rules... idiot rules*/
225- $ num_min_WR = $ initial_credit / $ rateinitial ;
226- $ num_sec_WR = intval ($ num_min_WR * 60 );
227- $ this ->tariffObj [0 ]['timeout_without_rules ' ] = $ num_sec_WR + $ this ->freetimetocall_left [0 ];
228- $ this ->tariffObj [0 ]['timeout ' ] = $ TIMEOUT + $ this ->freetimetocall_left [0 ];
229222
230- return $ TIMEOUT + $ this ->freetimetocall_left [0 ];
223+ if ($ TIMEOUT > $ MAGNUS ->config ['global ' ]['max_call_duration ' ]) {
224+ $ agi ->verbose ('TIMEOUT1 use max_call_duration ' . $ MAGNUS ->config ['global ' ]['max_call_duration ' ], 5 );
225+ $ TIMEOUT = $ MAGNUS ->config ['global ' ]['max_call_duration ' ];
226+ }
227+ $ this ->tariffObj [0 ]['timeout ' ] = $ TIMEOUT + $ this ->freetimetocall_left [0 ];
228+ return $ TIMEOUT ;
231229 }
232230
233231 public function calculateCost (&$ MAGNUS , $ callduration , $ agi )
@@ -464,7 +462,7 @@ public function updateSystem(&$MAGNUS, &$agi, $doibill = 1, $didcall = 0, $callb
464462 $ MAGNUS ->credit = $ MAGNUS ->credit - $ cost ;
465463 /*CALULATION CUSTO AND SELL RESELLER */
466464
467- if (! is_null ($ MAGNUS ->id_agent ) && $ MAGNUS ->id_agent > 1 ) {
465+ if ( ! is_null ($ MAGNUS ->id_agent ) && $ MAGNUS ->id_agent > 1 ) {
468466 $ agi ->verbose ('$MAGNUS->id_agent ' . $ MAGNUS ->id_agent . ' ' . $ MAGNUS ->destination . ' - ' .
469467 $ calldestinationPortabilidade . ' - ' . $ this ->real_answeredtime . ' - ' . $ cost , 1 );
470468
@@ -539,7 +537,7 @@ public function updateSystem(&$MAGNUS, &$agi, $doibill = 1, $didcall = 0, $callb
539537 public function updateSystemAgent ($ agi , $ MAGNUS , $ calledstation , $ cost , $ sessiontime )
540538 {
541539
542- if (! isset ($ MAGNUS ->modelRateAgent [0 ]['rateinitial ' ])) {
540+ if ( ! isset ($ MAGNUS ->modelRateAgent [0 ]['rateinitial ' ])) {
543541 $ agi ->verbose ('NOT FOUND AGENT TARRIF, USE AGENT COST PRICE ' );
544542 $ cost_customer = $ cost ;
545543 } else {
@@ -565,7 +563,7 @@ public function updateSystemAgent($agi, $MAGNUS, $calledstation, $cost, $session
565563
566564 public function sendCall ($ agi , $ destination , &$ MAGNUS , $ typecall = 0 )
567565 {
568- if (substr ("$ destination " , 0 , 4 ) == 1111 ) /*Retira o techprefix de numeros portados*/ {
566+ if (substr ("$ destination " , 0 , 4 ) == 1111 ) /*Retira o techprefix de numeros portados*/ {
569567 $ destination = str_replace (substr ($ destination , 0 , 7 ), "" , $ destination );
570568 }
571569 $ old_destination = $ destination ;
@@ -580,7 +578,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
580578 }
581579 $ modelTrunks = $ agi ->query ($ sql )->fetchAll (PDO ::FETCH_OBJ );
582580
583- if (! isset ($ modelTrunks [0 ]->id )) {
581+ if ( ! isset ($ modelTrunks [0 ]->id )) {
584582 $ MAGNUS ->hangup ($ agi , 34 );
585583 return ;
586584 }
@@ -634,7 +632,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
634632 }
635633 }
636634 if ($ typecall == 1 ) {
637- $ timeout = 3600 ;
635+ $ timeout = $ MAGNUS -> config [ ' global ' ][ ' max_call_duration ' ] ;
638636 }
639637
640638 if ($ modelTrunk ->credit_control == 1 && $ provider_credit <= 0 ) {
@@ -751,7 +749,7 @@ public function callShop($agi, $MAGNUS, $sessiontime, $id_prefix, $cost)
751749 AND id_user= $ MAGNUS ->id_user ORDER BY LENGTH(dialprefix) DESC LIMIT 1 " ;
752750 $ modelReteCallshop = $ agi ->query ($ sql )->fetch (PDO ::FETCH_OBJ );
753751
754- if (! isset ($ modelReteCallshop ->id )) {
752+ if ( ! isset ($ modelReteCallshop ->id )) {
755753 $ agi ->verbose ('Not found CallShop rate => ' . $ MAGNUS ->destination . ' ' . $ MAGNUS ->id_user );
756754 return ;
757755 }
@@ -799,11 +797,11 @@ public function saveCDR($agi, $MAGNUS, $returnID = false)
799797 $CalcAgi->saveCDR($agi, $MAGNUS);
800798 */
801799
802- if ($ this ->sipiax == 3 && !preg_match ('/\_WT/ ' , $ MAGNUS ->sip_account )) {
800+ if ($ this ->sipiax == 3 && ! preg_match ('/\_WT/ ' , $ MAGNUS ->sip_account )) {
803801 //if call is a DID, check is sipaccount is valid, else, set the callerid
804802 $ sql = "SELECT name FROM pkg_sip WHERE name = ' " . $ MAGNUS ->sip_account . "' LIMIT 1 " ;
805803 $ modelSipaccount = $ agi ->query ($ sql )->fetch (PDO ::FETCH_OBJ );
806- if (! isset ($ modelSipaccount ->name )) {
804+ if ( ! isset ($ modelSipaccount ->name )) {
807805 $ MAGNUS ->sip_account = $ MAGNUS ->CallerID ;
808806 }
809807 }
0 commit comments