| 2440 | | |
|---|
| 2441 | | |
|---|
| | 2440 | |
|---|
| | 2441 | |
|---|
| | 2442 | /* |
|---|
| | 2443 | * Function deck_switch |
|---|
| | 2444 | * to switch the Callplan from a customer : callplan_deck_minute_threshold |
|---|
| | 2445 | * |
|---|
| | 2446 | */ |
|---|
| | 2447 | function deck_switch($agi) |
|---|
| | 2448 | { |
|---|
| | 2449 | if (strpos($this->agiconfig['callplan_deck_minute_threshold'], ',') === false) |
|---|
| | 2450 | return false; |
|---|
| | 2451 | |
|---|
| | 2452 | $arr_splitable_deck = explode(",", $this->agiconfig['callplan_deck_minute_threshold']); |
|---|
| | 2453 | |
|---|
| | 2454 | foreach ($arr_splitable_deck as $arr_value) { |
|---|
| | 2455 | |
|---|
| | 2456 | $arr_value = trim ($arr_value); |
|---|
| | 2457 | $arr_value_explode = explode(":", $arr_value,2); |
|---|
| | 2458 | if (count($arr_value_explode) > 1){ |
|---|
| | 2459 | if (is_numeric($arr_value_explode[0]) && is_numeric($arr_value_explode[1]) ){ |
|---|
| | 2460 | $arr_value_deck_callplan[] = $arr_value_explode[0]; |
|---|
| | 2461 | $arr_value_deck_minute[] = $arr_value_explode[1]; |
|---|
| | 2462 | } |
|---|
| | 2463 | }else{ |
|---|
| | 2464 | if (is_numeric($arr_value)){ |
|---|
| | 2465 | $arr_value_deck_callplan[] = $arr_value; |
|---|
| | 2466 | $arr_value_deck_minute[] = 0; |
|---|
| | 2467 | } |
|---|
| | 2468 | } |
|---|
| | 2469 | } |
|---|
| | 2470 | // We have $arr_value_deck_callplan with 1, 2, 3 & we have $arr_value_deck_minute with 5, 1, 0 |
|---|
| | 2471 | if (count($arr_value_deck_callplan) == 0) |
|---|
| | 2472 | return false; |
|---|
| | 2473 | |
|---|
| | 2474 | $QUERY = "SELECT sum(sessiontime), count(*) FROM cc_call WHERE card_id='".$this->id_card."'"; |
|---|
| | 2475 | $result = $this->instance_table -> SQLExec ($this->DBHandle, $QUERY); |
|---|
| | 2476 | $this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[DECK SWITCH - Start]".print_r($result, true)); |
|---|
| | 2477 | $sessiontime_for_card = $result[0][0]; |
|---|
| | 2478 | $calls_for_card = $result[0][1]; |
|---|
| | 2479 | |
|---|
| | 2480 | $find_deck = false; |
|---|
| | 2481 | $accumul_seconds = 0; |
|---|
| | 2482 | for ($ind_deck = 0 ; $ind_deck < count($arr_value_deck_callplan) ; $ind_deck++){ |
|---|
| | 2483 | $accumul_seconds += $arr_value_deck_minute[$ind_deck]; |
|---|
| | 2484 | |
|---|
| | 2485 | if ($arr_value_deck_callplan[$ind_deck] == $this->tariff) { |
|---|
| | 2486 | if (is_numeric($arr_value_deck_callplan[$ind_deck+1])) { |
|---|
| | 2487 | $find_deck = true; |
|---|
| | 2488 | } else { |
|---|
| | 2489 | $find_deck = false; |
|---|
| | 2490 | } |
|---|
| | 2491 | break; |
|---|
| | 2492 | } |
|---|
| | 2493 | } |
|---|
| | 2494 | |
|---|
| | 2495 | $ind_deck = $ind_deck + 1; |
|---|
| | 2496 | if ($find_deck) { |
|---|
| | 2497 | // Check if the sum sessiontime call is more the the accumulation of the parameters seconds & that the amount of calls made is upper than the deck level |
|---|
| | 2498 | if (($sessiontime_for_card > $accumul_seconds) && ($calls_for_card > $ind_deck)) { |
|---|
| | 2499 | // UPDATE CARD |
|---|
| | 2500 | $this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[DECK SWITCH] : UPDATE CARD TO CALLPLAN ID = ".$arr_value_deck_callplan[$ind_deck]); |
|---|
| | 2501 | $QUERY = "UPDATE cc_card SET tariff='".$arr_value_deck_callplan[$ind_deck]."' WHERE id='".$this->id_card."'"; |
|---|
| | 2502 | $result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY, 0); |
|---|
| | 2503 | |
|---|
| | 2504 | $this->tariff = $arr_value_deck_callplan[$ind_deck]; |
|---|
| | 2505 | } |
|---|
| | 2506 | } |
|---|
| | 2507 | return true; |
|---|
| | 2508 | } |
|---|
| | 2509 | |
|---|
| | 2510 | |
|---|
| | 2511 | /* |
|---|
| | 2512 | * Function DbConnect |
|---|
| | 2513 | * Returns: true / false if connection has been established |
|---|
| | 2514 | */ |
|---|