importar("Utilidades.Lista.ListaVendedores");
$tituloPagina = 'Utilidades > Vendedores > Alterar';
$iAT = new IFAdmin(new Arquivos(Sistema::$adminLayoutCaminhoDiretorio . "/SistemaUtilidades/vendedor.html"));
if (!empty($_POST)) {
    $erro = '';
    if (empty($_POST['nome'])) {
        $erro = "<b>Nome</b> não preenchido!<br><br>";
    }
    if (empty($_POST['email'])) {
        $erro = "<b>E-mail</b> não preenchido!<br><br>";
    }
    if (empty($erro)) {
        $lT = new ListaVendedores();
        $lT->condicoes('', $_GET['vendedor'], ListaVendedores::ID);
        $tx = $lT->listar();
        $tx->nome = $_POST['nome'];
        $tx->email = $_POST['email'];
        $tx->msn = $_POST['msn'];
        $tx->skype = $_POST['skype'];
        $tx->voip = $_POST['voip'];
        $tx->telefone = $_POST['telefone'];
        $tx->ramal = $_POST['ramal'];
        $tx->ordem = $_POST['ordem'];
        if (!empty($_FILES['imagem']['name'])) {
            $tx->getImagem()->setImage(new Image(Arquivos::__OpenArquivoByTEMP($_FILES['imagem'])));
        }
        $lT->alterar($tx);
        $javaScript .= Aviso::criar("Vendedor salvo com sucesso!");
    } else {
        $javaScript .= Aviso::criar($erro);
    if ($lT->getTotal() > 0) {
        try {
            $lT->deletar($lT->listar());
            $javaScript .= Aviso::criar("Vendedor removido com sucesso!");
        } catch (Exception $e) {
            $javaScript .= Aviso::criar($e->getMessage());
        }
    }
}
$lT = new ListaVendedores();
$ILT->createRepeticao("repetir->Vendedores");
if (!empty($_GET['busca'])) {
    $lT->condicoes('', "%" . $_GET['busca'] . "%", 'empresa', 'LIKE');
}
$ILT->condicao("condicaoBusca", !empty($_SESSION['nivel']));
$ILT->trocar("linkCadastrar.Vendedores", "?p=" . $_GET['p'] . "&a=cadastrarVendedor");
$lT->condicoes($a);
while ($tx = $lT->listar("ASC", ListaVendedores::NOME)) {
    $ILT->repetir();
    $ILT->enterRepeticao()->condicao("condicaoRemover", !empty($_SESSION['nivel']));
    $bgColor = $lT->getParametros() % 2 == 0 ? '#FFFFFF' : '#EAEAEA';
    $ILT->enterRepeticao()->trocar("bgColorEmpresa", $bgColor);
    $ILT->enterRepeticao()->trocar("id.Vendedores", $tx->getId());
    $ILT->enterRepeticao()->trocar("titulo.Vendedores", $tx->nome);
    $ILT->enterRepeticao()->trocar("linkVisualizar.Vendedores", "?p=" . $_GET['p'] . "&a=listarVendedor&vendedor=" . $tx->getId());
    $ILT->enterRepeticao()->trocar("linkAlterar.Vendedores", "?p=" . $_GET['p'] . "&a=alterarVendedor&vendedor=" . $tx->getId());
    $ILT->enterRepeticao()->condicao("condicaoVisualizar", $tx->tipo == 1);
}
$botoes = $ILT->cutParte('botoes');
$ILT->trocar('link.Voltar', "?p=" . $_GET['p'] . "&a=produtos");
$includePagina = $ILT->concluir();