PABX da Simples IP
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.
 
 
 
 
 
 

140 lines
5.1 KiB

<?php
include __DIR__ . "/kingDiscador.php";
$tpLayout = 1;
$template = "discador/cadCampKing.tpl";
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$login = isset($_POST['login']) ? $_POST['login'] : 'simples';
$horaini = isset($_POST['horaini']) ? $_POST['horaini'] : '07:00';
$horafim = isset($_POST['horafim']) ? $_POST['horafim'] : '20:59';
$ramal = isset($_POST['ramal']) ? $_POST['ramal'] : '1000';
$fluxo = isset($_POST['fluxo']) ? $_POST['fluxo'] : '0';
$numrediscagem = isset($_POST['numrediscagem']) ? $_POST['numrediscagem'] : 1;
$maxcall = isset($_POST['maxcall']) ? $_POST['maxcall'] : 10;
$ringtime = isset($_POST['ringtime']) ? $_POST['ringtime'] : 45;
$intervalo = isset($_POST['intervalo']) ? $_POST['intervalo'] : 1;
$maxcallagent = isset($_POST['maxcallagent']) ? $_POST['maxcallagent'] : 3;
$nds = isset($_POST['nds']) ? $_POST['nds'] : '0';
$pausa = isset($_POST['pausa']) ? $_POST['pausa'] : 1;
$amd = isset($_POST['amd']) ? $_POST['amd'] : '0';
$priomovel = isset($_POST['priomovel']) ? $_POST['priomovel'] : '0';
$column = array('king_camp_login', 'king_camp_horaini', 'king_camp_horafim',
'king_camp_ramal', 'king_camp_fluxo', 'king_camp_numrediscagem', 'king_camp_maxcall',
'king_camp_ringtime', 'king_camp_intervalo', 'king_camp_maxcallagent', 'king_camp_nds',
'king_camp_pausa', 'king_camp_amd', 'king_camp_priomovel');
try {
/**
* INICIA CONF. DO BANCO
*/
connectMysql();
/**
* ID DE CONFIGURACAO GERAL = 1
*/
if ($id > 1 && !isset($_POST['execute'])) {
$campanha = campanhasPausa($id);
foreach ($column as $key => $value) {
if ($value == "king_camp_horaini") {
$column[$value] = explode(" ", $campanha['datetime_ini'])[1];
} else if ($value == "king_camp_horafim") {
$column[$value] = explode(" ", $campanha['datetime_fin'])[1];
} else {
$column[$value] = $campanha[str_replace('king_camp_', "", $value)];
}
unset($column[$key]);
}
} else {
/**
* CONFIGURACOES DEFAULT
*/
foreach ($column as $key => $value) {
$column[$value] = ${str_replace('king_camp_', "", $value)};
unset($column[$key]);
}
$resp = GetConfiguracao($dbcon);
}
/**
* ALTERA AS CONFIGURACOES DE UMA CAMPANHA DO KING
*/
if($id > 1 && isset($_POST['execute'])){
alteraCampanhaKing($id, $column);
$message = GetMessage("A configura<EFBFBD><EFBFBD>o foi executada com sucesso!", 'S');
unset($resp);
}
/**
* ALTERA AS CONFIGURACOES GERAL DO KING
*/
if (isset($_POST['execute']) && $id <= 1) {
SetConfiguracao($dbcon, $column);
if (pg_last_error()) {
throw new Exception('N<EFBFBD>o foi poss<EFBFBD>vel salvar as configura<EFBFBD><EFBFBD>es!');
}
$message = GetMessage("A configura<EFBFBD><EFBFBD>o foi executada com sucesso!", 'S');
$resp = GetConfiguracao($dbcon);
}
} catch (Exception $ex) {
$message = GetMessage($ex->getMessage(), 'E');
}
$smarty->assign("message", $message);
$smarty->assign("id", $resp['id_camp_king'] ? $resp['id_camp_king'] : $id);
foreach ($column as $key => $value) {
$smarty->assign(str_replace("king_camp_", "", $key), $resp[$key] ? $resp[$key] : $value);
}
/*
* Carrega o template correspondente ao cadastro
*/
GetTemplate($smarty, $template);
function GetConfiguracao($dbcon) {
$query = "SELECT * FROM pbx_kingdialer_campanha WHERE id_camp_king = 1";
$result = pg_query($dbcon, $query);
return pg_fetch_assoc($result);
}
function SetConfiguracao($dbcon, $column) {
$resp = GetConfiguracao($dbcon);
if (!$resp['id_camp_king']) {
foreach ($column as $key => $values) {
$column[$key] = QuotedStr($values);
}
$query = "INSERT INTO pbx_kingdialer_campanha (" . implode(',', array_keys($column)) . ") VALUES (" . implode(',', array_values($column)) . ");";
} else {
$query = "UPDATE pbx_kingdialer_campanha SET ";
$x = 0;
foreach ($column as $key => $value) {
$x++;
$query .= "$key = '{$value}'";
if ($x != count($column)) {
$query .= ", ";
}
}
$query .= " WHERE id_camp_king = {$resp['id_camp_king']}";
}
pg_query($dbcon, $query);
}
function GetMessage($message, $type) {
if (strtoupper($type) == 'E' || strtoupper($type) == 'ERRO') {
return "<h3 style='color:red'><b>ERRO: </b>$message</h3>";
}
if (strtoupper($type) == 'S' || strtoupper($type) == 'SUCESSO') {
return "<h3 style='color:green'><b>SUCESSO: </b>$message</h3>";
}
}
?>