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.
 
 
 
 
 
 

103 lines
2.9 KiB

<?php
require('funcoesFormulario.php');
$templateName = 'pausaAtomaticaDac.htm';
//define tipo de formulario
$tpLayout = 1;
$upload = 0;
$fieldsForm = array();
$fieldsForm = IsPostBack() ? $_POST : $_GET;
$fieldsForm['erro'] = "";
if (isset($fieldsForm['btIncDac'])) {
if (empty($fieldsForm['listaDacs'])) {
$fieldsForm['erro'] = fmtMsg('Selecione um Dac!');
} else {
pg_query($dbcon, 'begin');
foreach ($fieldsForm['listaDacs'] as $idDac) {
$query = "insert into pbx_pausa_automatica(idDac)values('%s')";
$query = sprintf($query, $idDac);
$result = pg_query($dbcon, $query);
if (!$result)
break;
}
if ($result)
pg_query($dbcon, 'commit');
else
pg_query($dbcon, 'rollback');
$fieldsForm['erro'] = $result ? fmtMsg('Dac incluido com sucesso!') : fmtErro('O Dac não pode ser incluido!', pg_last_error($dbcon));
}
}
else if (isset($fieldsForm['btRmDac'])) {
if (empty($fieldsForm['listaDacsInc'])) {
$fieldsForm['erro'] = fmtMsg('Selecione um agente!');
} else {
pg_query($dbcon, 'begin');
foreach ($fieldsForm['listaDacsInc'] as $idDac) {
$query = "delete from pbx_pausa_automatica where idDac = %s ";
$query = sprintf($query, $idDac);
$result = pg_query($dbcon, $query);
if (!$result)
break;
}
if ($result)
pg_query($dbcon, 'commit');
else
pg_query($dbcon, 'rollback');
$fieldsForm['erro'] = $result ? fmtMsg('Dac removido com sucesso!') : fmtErro('O Dac não pode ser removido!', pg_last_error($dbcon));
}
}
$fieldsForm['listaDacs'] = GetDacPausa($dbcon, 'listaDacs', $codDac);
$fieldsForm['listaDacsInc'] = GetDacPausa($dbcon, 'listaDacsInc', $codDac, true);
/*
* Atualiza templates templates
*/
foreach ($fieldsForm as $key => $value) {
$smarty->assign($key, $value);
}
GetTemplate($smarty, $templateName);
function GetDacPausa($dbcon, $nomeCombo, $codDac = 0, $inc = false) {
$dacs = "<select name=\"$nomeCombo" . "[]" . "\" style=\"width:280px\" id=\"$nomeCombo\" size=\"8\" multiple=\"multiple\">";
$query = "select id, nome from pbx_dacs a";
if ($inc) {
$query .= " where 1=1 and ";
} else {
$query .= " where 1=1 and not ";
}
$query .= " exists(select '' from pbx_pausa_automatica where idDac = a.id)";
$query .= " order by 2 \n";
$result = pg_query($dbcon, $query);
while ($dados = pg_fetch_row($result)) {
if ($codSel == $dados[0]) {
$sel = "selected";
$i = 1;
} else {
$sel = "";
}
$dacs .= "<option value=\"$dados[0]\" $sel>$dados[1]</option>";
}
$dacs .= "</select>";
return $dacs;
}
?>