forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.9 KiB
117 lines
3.9 KiB
<?php |
|
|
|
/* |
|
* Configuration of database. |
|
*/ |
|
//$conStr = sprintf("host='%s' port='%s' dbname='%s' user='%s' password='%s'", '127.0.0.1', '5432', 'pbx', 'contacte', 'ctepgSQL'); |
|
$connPG = pg_connect(GetDefStrDb()); |
|
|
|
function RegistraIntegracao($reg_id_metodo, $reg_uniqueid, $reg_uniqueid_old, $reg_fone) { |
|
global $connPG, $tronco, $ura; |
|
|
|
$valUra = trim($ura); |
|
$valUra = $valUra ? "'$valUra'" : 'null'; |
|
|
|
$valTronco = trim($tronco); |
|
$valTronco = $valTronco ? "'$valTronco'" : 'null'; |
|
$row = array(); |
|
$query = "insert into pbx_integracao_reg |
|
(reg_id_metodo, reg_uniqueid, reg_uniqueid_old, reg_fone, reg_inicio, reg_tronco, reg_ura) |
|
values ( '$reg_id_metodo', '$reg_uniqueid', '$reg_uniqueid_old', '$reg_fone', now(), $valTronco, $valUra)"; |
|
|
|
$result = (pg_query($connPG, $query) !== false); |
|
return $result; |
|
} |
|
|
|
function AtualizaIntegracao($reg_uniqueid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente = '') { |
|
/* |
|
* $reg_status_exec |
|
* 0 |
|
*/ |
|
global $tronco, $ura; |
|
$valTronco = trim($tronco); |
|
$valTronco = $valTronco ? ",\nreg_tronco='$valTronco'" : ''; |
|
|
|
$valUra = trim($ura); |
|
$valUra = $valUra ? ",\nreg_ura='$valUra'" : ''; |
|
|
|
|
|
$reg_msg = QuotedStr($reg_msg); |
|
$reg_retorno = QuotedStr($reg_retorno); |
|
$retorno_cliente = substr($retorno_cliente, 0, 255); |
|
$connPG = $GLOBALS['connPG']; |
|
$query = "update pbx_integracao_reg |
|
set reg_fim = now(), |
|
reg_retorno = $reg_retorno, |
|
reg_msg = $reg_msg, |
|
reg_status_exec = '$reg_status_exec', |
|
retorno_cliente = '$retorno_cliente' $valTronco $valUra |
|
where reg_uniqueid = '$reg_uniqueid'"; |
|
|
|
$result = (pg_query($connPG, $query) !== false); |
|
return $result; |
|
} |
|
|
|
function AtualizaEvento($reg_uniqueid, $reg_msg_evt, $evento = 0) { |
|
/* |
|
* $reg_status_exec |
|
* 0 reg_msg_evt varchar(1024), add reg_data_evt |
|
*/ |
|
$reg_msg_evt = QuotedStr($reg_msg_evt); |
|
$connPG = $GLOBALS['connPG']; |
|
$query = "update pbx_integracao_reg |
|
set reg_msg_evt = $reg_msg_evt, |
|
reg_status = '$evento', |
|
reg_data_evt = now() |
|
where reg_uniqueid = '$reg_uniqueid'"; |
|
|
|
$result = (pg_query($connPG, $query) !== false); |
|
return $result; |
|
} |
|
|
|
function GetInfoMetodo($idMetodo) { |
|
$connPG = $GLOBALS['connPG']; |
|
$row = array(); |
|
$query = "select a.itgm_tipo, a.itgm_comando, itgm_retorno, a.opcao as opcao_metodo, a.stored_params, |
|
c.itgp_prefix, b.itgc_host, b.itgc_port, b.itgc_database, b.itgc_user, b.itgc_password, |
|
b.itgc_timeout, b.opcao, b.acao, coalesce(a.evento, 0) as evento |
|
from pbx_integracao_metodo a, pbx_integracao_configuracao b, pbx_integracao_protocolo c |
|
where b.itgc_id = a.itgc_id |
|
and c.itgp_id = b.itgp_id |
|
and a.itgm_id = '$idMetodo'"; |
|
$result = pg_query($connPG, $query); |
|
|
|
if ($result) { |
|
$row = pg_fetch_array($result); |
|
return $row; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
function dadosIntegra($id) { |
|
$connPG = $GLOBALS['connPG']; |
|
$row = array(); |
|
$query = "select int_dados from pbx_integracao_dados where int_id = '$id'"; |
|
$result = pg_query($connPG, $query); |
|
$row = pg_fetch_array($result); |
|
return $row[0]; |
|
} |
|
|
|
function grava_dadosIntegra($id) { |
|
$connPG = $GLOBALS['connPG']; |
|
|
|
$query = "select retorno_cliente from pbx_integracao_reg where reg_retorno = '$id' order by datareg desc limit 1"; |
|
$result = pg_query($connPG, $query); |
|
$row = pg_fetch_array($result); |
|
$dado = $row[0]; |
|
|
|
$sql = "insert into pbx_integracao_dados(int_id,int_dados) " |
|
. "values('$id','$dado')"; |
|
|
|
$result2 = (pg_query($connPG, $sql) !== false); |
|
|
|
return $result2; |
|
} |
|
|
|
?>
|
|
|