function leerDatosGrafico($type_graph, $date_start, $date_end) { global $arrConf; global $arrConfModule; global $arrLang; $MAX_SLICES = 10; $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $pDBSQLite = new paloDB($arrConfModule['dsn_conn_database_2']); if (!empty($pDBSQLite->errMsg)) { echo "{$arrLang['ERROR']}: {$pDBSQLite->errMsg} <br>"; } $pRate = new paloRate($pDBSQLite); if (!empty($pRate->errMsg)) { echo "{$arrLang['ERROR']}: {$pRate->errMsg} <br>"; } $pDBSet = new paloDB($arrConf['elastix_dsn']['settings']); $pDBTrunk = new paloDB($arrConfModule['dsn_conn_database_1']); $oTrunk = new paloTrunk($pDBTrunk); $grupos = NULL; $troncales = $oTrunk->getExtendedTrunksBill($grupos, $arrConfig['ASTETCDIR']['valor'] . '/chan_dahdi.conf'); //ej array("DAHDI/1","DAHDI/2"); $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asteriskcdrdb"; $pDB = new paloDB($dsn); $oCDR = new paloSantoCDR($pDB); $arrCDR = $oCDR->obtenerCDRs("", 0, $date_start, $date_end, "", "", "ANSWERED", "outgoing", $troncales); $total = $arrCDR['NumRecords'][0]; $num_calls = array(); $minutos = array(); $val_charge = array(); $nombre_rate = array(); $title_sumary = NULL; if ($total > 0) { foreach ($arrCDR['Data'] as $cdr) { if (eregi("^DAHDI/([[:digit:]]+)", $cdr[4], $regs3)) { $trunk = 'DAHDI/g' . $grupos[$regs3[1]]; } else { $trunk = str_replace(strstr($cdr[4], '-'), '', $cdr[4]); } //tengo que buscar la tarifa para el numero de telefono $numero = $cdr[2]; $tarifa = array(); $rate_name = ""; $charge = 0; $bExito = $pRate->buscarTarifa($numero, $tarifa, $trunk); if (!count($tarifa) > 0 && $bExito) { $bExito = $pRate->buscarTarifa($numero, $tarifa, 'None'); } if (!$bExito) { echo "{$arrLang['ERROR']}: {$pRate->errMsg} <br>"; } else { //verificar si tiene tarifa if (count($tarifa) > 0) { foreach ($tarifa as $id_tarifa => $datos_tarifa) { $rate_name = $datos_tarifa['name']; $id_rate = $datos_tarifa['id']; $charge = $cdr[8] / 60 * $datos_tarifa['rate'] + $datos_tarifa['offset']; } } else { $rate_name = $arrLang["default"]; $id_rate = 0; //no tiene tarifa buscar tarifa por omision //por ahora para probar $1 el minuto $rate = get_key_settings($pDBSet, "default_rate"); $rate_offset = get_key_settings($pDBSet, "default_rate_offset"); $charge = $cdr[8] / 60 * $rate + $rate_offset; } $nombre_rate[$id_rate] = $rate_name; if (!isset($minutos[$id_rate])) { $minutos[$id_rate] = 0; } if (!isset($num_calls[$id_rate])) { $num_calls[$id_rate] = 0; } if (!isset($val_charge[$id_rate])) { $val_charge[$id_rate] = 0; } $minutos[$id_rate] += $cdr[8] / 60; $num_calls[$id_rate]++; $val_charge[$id_rate] += $charge; } } //ordenar los valores a mostrar arsort($num_calls); arsort($minutos); arsort($val_charge); //verificar que los valores no excedan el numero de slices del pie //numero de llamadas if (count($num_calls) > $MAX_SLICES) { $i = 1; foreach ($num_calls as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_num_calls['otros'])) { $valores_num_calls['otros'] = 0; } $valores_num_calls['otros'] += $valor; } else { $valores_num_calls[$id_rate] = $valor; } $i++; } } else { $valores_num_calls = $num_calls; } //minutos if (count($minutos) > $MAX_SLICES) { $i = 1; foreach ($minutos as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_minutos['otros'])) { $valores_minutos['otros'] = 0; } $valores_minutos['otros'] += $valor; } else { $valores_minutos[$id_rate] = $valor; } $i++; } } else { $valores_minutos = $minutos; } //charge if (count($val_charge) > $MAX_SLICES) { $i = 1; foreach ($val_charge as $id_rate => $valor) { if ($i > $MAX_SLICES - 1) { if (!isset($valores_charge['otros'])) { $valores_charge['otros'] = 0; } $valores_charge['otros'] += $valor; } else { $valores_charge[$id_rate] = $valor; } $i++; } } else { $valores_charge = $val_charge; } if ($type_graph == "minutes") { $titulo = $arrLang["Distribution by Time"]; $valores_grafico = $valores_minutos; $title_sumary = $arrLang["Minutes"]; } elseif ($type_graph == "charge") { $titulo = $arrLang["Distribution by Cost"]; $valores_grafico = $valores_charge; $title_sumary = $arrLang["Cost"]; } else { $titulo = $arrLang["Distribution by Number of Calls"]; $valores_grafico = $valores_num_calls; $title_sumary = $arrLang["Number of Calls"]; } //nombres de tarifas para leyenda foreach ($valores_grafico as $id => $valor) { $nombres_tarifas[] = isset($nombre_rate[$id]) ? $nombre_rate[$id] : $arrLang["others"]; } $data = array_values($valores_grafico); } else { if ($type_graph == "minutes") { $titulo = $arrLang["Distribution by Time"]; } elseif ($type_graph == "charge") { $titulo = $arrLang["Distribution by Cost"]; } else { $titulo = $arrLang["Distribution by Number of Calls"]; } $nombres_tarifas = $data = array(); } //formar la estructura a pasar al pie $data_graph = array("values" => $data, "legend" => $nombres_tarifas, "title" => $titulo, "title_sumary" => $title_sumary); return $data_graph; }