Browse Source

Removido opcao do usuario escolher empresa master

1.9
Matheo Bonucia 2 months ago
parent
commit
d659e840f5
  1. 40
      cadastros/organizacao/cadOrganizacao.php
  2. 8
      templates/cadastros/organizacao/cadOrganizacao.tpl

40
cadastros/organizacao/cadOrganizacao.php

@ -6,12 +6,11 @@ $tpLayout = 1;
$id = isset($_GET["id"]) ? $_GET["id"] : $_POST["id"];
$nome = isset($_POST["nome"]) ? $_POST["nome"] : null;
$status = isset($_POST["status"]);
$master = isset($_POST["master"]);
try {
if (isset($_POST["btGravar"])) {
$ret = setOrganizacao($dbcon, ['nome' => $nome, 'status' => $status, 'master' => $master], $id);
$ret = setOrganizacao($dbcon, ['nome' => $nome, 'status' => $status,], $id);
}
if ($id || $ret) {
@ -31,7 +30,6 @@ try {
$smarty->assign("id", $id);
$smarty->assign("nome", $nome);
$smarty->assign("status", $status ? "checked" : "");
$smarty->assign("master", $master ? "checked" : "");
$smarty->assign("acaoUser", $acaoUser);
GetTemplate($smarty, 'cadastros/organizacao/cadOrganizacao.tpl');
@ -43,21 +41,16 @@ function setOrganizacao($dbcon, $dados, $id = null)
throw new Exception($isExists ? "O nome da organização já existe!" : "Por favor, preencha o campo nome!");
}
$isExistsMaster = verificaMaster($dbcon);
if ($isExistsMaster == true && $dados['master'] == "checked") {
throw new Exception("Já existe uma empresa master ativa!");
}
if ($id) {
$query = "UPDATE pbx_organizacao
SET nome = %s,
status = %s,
master = %s
WHERE id = %s;";
$query = sprintf($query, QuotedStr($dados['nome']), $dados['status'] == "checked" ? 1 : 0, $dados['master'] == "checked" ? 1 : 0, $id);
status = %d,
master = %d
WHERE id = %d;";
$query = sprintf($query, QuotedStr($dados['nome']), $dados['status'] == "checked" ? 1 : 0, 0, $id);
} else {
$query = "INSERT INTO pbx_organizacao (nome, status, master) VALUES(%s, %s, %s) RETURNING id";
$query = sprintf($query, QuotedStr($dados['nome']), $dados['status'] == "checked" ? 1 : 0, $dados['master'] == "checked" ? 1 : 0);
$query = "INSERT INTO pbx_organizacao (nome, status, master) VALUES(%s, %d, %d) RETURNING id";
$query = sprintf($query, QuotedStr($dados['nome']), $dados['status'] == "checked" ? 1 : 0, 0);
}
$result = pg_query($dbcon, $query);
@ -209,22 +202,3 @@ function ___Gravalog($message)
$line .= "----------------------------------------------";
file_put_contents('/var/log/asterisk/cadOrganizacao.log', $line, FILE_APPEND);
}
function verificaMaster($dbcon)
{
$query = "SELECT id, master, status FROM pbx_organizacao;";
$result = pg_query($dbcon, $query);
$resposta = false;
if (!$result) {
throw new Exception("Não foi possível verificar se existe organizaçao master!");
}
$dados = pg_fetch_all($result);
if ($dados) {
foreach ($dados as $linha) {
if ($linha['master'] == 1 && $linha['status'] == 1) {
$resposta = true;
}
}
}
return $resposta;
}

8
templates/cadastros/organizacao/cadOrganizacao.tpl

@ -10,14 +10,6 @@
<th width="120" align="left">Nome da Organização</th>
<td><input name="nome" type="text" id="nome" value="{$nome}" size="60" maxlength="60" ></td>
</tr>
{if isAdmin()}
<tr>
<th align="left">Empresa Master</th>
<td>
<input name="master" type="checkbox" id="status" value= "1" {$master}>
</td>
</tr>
{/if}
<tr>
<th align="left">Status</th>
<td>

Loading…
Cancel
Save