ok

Mini Shell

Direktori : /home/pequenacapitolio/www/administrador/
Upload File :
Current File : /home/pequenacapitolio/www/administrador/destaque_admin.php

<?php

include '../conexao.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// ############# INSERE DESTAQUE ###################
if (isset($_GET["act"]) && $_GET["act"] == "inserir" && isset($_POST["submit"])) {
    $titulo_dest = $_POST["titulo"];
    $pag_categoria = $_POST["categoria"];
    $subtitulo_dest = $_POST["subtitulo"];
    $link_dest = $_POST["link"];

    // ################## UPLOAD DE ARQUIVOS (NÃO ME PERGUNTE COMO FUNCIONA, APENAS FUNCIONA) ###############
    $currentDir = getcwd();
    $uploadDirectory = "/uploads/imagens/";

    $errors = []; // Store all foreseen and unforseen errors here

    $fileExtensions = ['jpeg','jpg','png']; // Get all the file extensions

    $fileName = $_FILES['myfile']['name'];
    $fileSize = $_FILES['myfile']['size'];
    $fileTmpName  = $_FILES['myfile']['tmp_name'];
    $fileType = $_FILES['myfile']['type'];
    $fileExtension = strtolower(end(explode('.',$fileName)));

    $uploadPath = $currentDir . $uploadDirectory . basename($fileName); 

    if (isset($_POST['submit'])) {

        if (! in_array($fileExtension,$fileExtensions)) {
            $errors[] = "Esta extensão de arquivo não é permitida. Por favor, faça o upload de um arquivo JPEG ou PNG";
        }

        if ($fileSize > 2000000) {
            $errors[] = "Este arquivo tem mais de 2MB. Desculpe, tem que ser menor ou igual a 2MB";
        }

        if (empty($errors)) {
            $didUpload = move_uploaded_file($fileTmpName, $uploadPath);

            if ($didUpload) {
                echo "O Arquivo " . basename($fileName) . " foi enviado";
            } else {
                echo "Um erro ocorreu em algum lugar. Tente novamente ou entre em contato com o administrador";
            }
        } else {
            foreach ($errors as $error) {
                echo $error . "Estes são os erros" . "\n";
            }
        }
    }

    $dados_dest = array(
        'titulo' => $titulo_dest,
        'subtitulo' => $subtitulo_dest,
        'link' => $link_dest,
        'categoria' => $pag_categoria,
        'foto' => $_FILES["myfile"]["name"]

    );

    $conn->prepare("INSERT INTO destaque (titulo, subtitulo, foto, link, id_categoria) VALUES (:titulo, :subtitulo, :foto, :link, :categoria)")->execute($dados_dest);

    $redirect = "/administrador/destaque_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/destaque_admin.php";
    header("location:$redirect");

}

// ############# DELETA DESTAQUE ###################
if (isset($_GET["act"]) && $_GET["act"] == "excluir") {
    $dest_exclui = $_GET["id"];

    $dados_dest = array(
        'id' => $dest_exclui,
    );

    $conn->prepare("DELETE FROM destaque WHERE iddestaque = :id")->execute($dados_dest);

    $redirect = "/administrador/destaque_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/destaque_admin.php";
    header("location:$redirect");
}

// ############# UPDATE DESTAQUE ###################
if (isset($_GET["act"]) && $_GET["act"] == "editar") {

    $dest_id = $_GET["id"];
    $dest_titulo = $_POST["titulo"];
    $dest_subtitulo = $_POST["subtitulo"];
    $link_dest = $_POST["link"];
    $categoria_edita = $_POST["categoria"];


    $dados_dest = array(
        'id' => $dest_id,
        'titulo' => $dest_titulo,
        'subtitulo' => $dest_subtitulo,
        'categoria' => $categoria_edita,
        'link' => $link_dest
      );

    $conn->prepare("UPDATE destaque SET titulo = :titulo, subtitulo = :subtitulo, link = :link, id_categoria = :categoria WHERE iddestaque = :id")->execute($dados_dest);

    $redirect = "/administrador/destaque_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/destaque_admin.php";
    header("location:$redirect");
}



// ############# UPDATE DESTAQUE FOTO ###################
if (isset($_GET["act"]) && $_GET["act"] == "foto") {

  $dest_id = $_GET["id"];


  // ################## UPLOAD DE ARQUIVOS (NÃO ME PERGUNTE COMO FUNCIONA, APENAS FUNCIONA) ###############
  $currentDir = getcwd();
  $uploadDirectory = "/uploads/imagens/";

  $errors = []; // Store all foreseen and unforseen errors here

  $fileExtensions = ['jpeg','jpg','png']; // Get all the file extensions

  $fileName = $_FILES['myfile']['name'];
  $fileSize = $_FILES['myfile']['size'];
  $fileTmpName  = $_FILES['myfile']['tmp_name'];
  $fileType = $_FILES['myfile']['type'];
  //$fileExtension = strtolower(end(explode('.',$fileName)));

  $uploadPath = $currentDir . $uploadDirectory . basename($fileName); 

  if (isset($_POST['submit'])) {

      // if (! in_array($fileExtension,$fileExtensions)) {
      //     $errors[] = "Esta extensão de arquivo não é permitida. Por favor, faça o upload de um arquivo JPEG ou PNG";
      // }

      // if ($fileSize > 2000000) {
      //     $errors[] = "Este arquivo tem mais de 2MB. Desculpe, tem que ser menor ou igual a 2MB";
      // }

      if (empty($errors)) {
          $didUpload = move_uploaded_file($fileTmpName, $uploadPath);

          if ($didUpload) {
              echo "O Arquivo " . basename($fileName) . " foi enviado";
          } else {
              echo "Um erro ocorreu em algum lugar. Tente novamente ou entre em contato com o administrador";
          }
      } else {
          foreach ($errors as $error) {
              echo $error . "Estes são os erros" . "\n";
          }
      }
  }

  $dados_titulo = array(
      'foto'  => $_FILES["myfile"]["name"],
      'id' => $dest_id
    );

  $conn->prepare("UPDATE destaque SET foto = :foto WHERE iddestaque = :id")->execute($dados_titulo);

  $redirect = "/administrador/destaque_admin.php";
  //$redirect = "http://www.tchaudor.com.br/administrador/destaque_admin.php";
  header("location:$redirect");
}
?>

<!DOCTYPE html>
<html>
<head>
    <?php include 'include_head.php';?>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- Site wrapper -->
<div class="wrapper">

  <?php include 'estrutura_menu.php';?>

  <!-- =============================================== -->

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
   <div class="col-md-12" style="background: #fff;border-bottom: 1px solid #bbbbbb">
      <div class="col-md-12" style="text-align: left;padding-left: 0px">
        <p style="color: #040404;font-weight: 700;font-size: 32px;margin-top: 1%;margin-bottom: 0px"">Gerenciamento de Destaque</p>
      </div>
      <div class="col-md-8" style="height: 34px;padding-left: 0px">
        <p style="color: #3a3a3a;font-size: 14px;">Tela Inicial/Gerenciamento de Destaque</p>
      </div>
      <div class="col-md-4" style="text-align: right;margin-bottom: 1%">
        <a href="categorias_destaque_admin.php" class="btn btn-primary btn-flat" style="margin-right: 4%">Gerenciar Categorias</a>
        <a href="#" data-toggle="modal" data-target="#modal-inserir" class="btn btn-primary btn-flat">Inserir Destaque</a>
      </div>
    </div>
    <div class="col-md-12" style="height: 22px">
      
    </div>
    
    <!-- Main content -->
    <section class="content">

    <?php

    $dest = $conn->query("SELECT destaque.iddestaque, destaque.titulo as titulodestaque, destaque.foto, categorias_destaques.titulo as titulocategoria FROM destaque inner join categorias_destaques on destaque.id_categoria = categorias_destaques.idcategorias order by iddestaque desc");

    ?>

    <div class="row">
        <div class="col-xs-12">
          <div class="box" style="border-top:5px solid #408db9">
            <div class="box-body table-responsive no-padding">
               <!--  <a href="#" data-toggle="modal" data-target="#modal-inserir" class="btn btn-primary btn-flat" style="float:right; margin:20px;">Inserir Destaque</a> -->
            </div>

            <?php if ($dest->rowCount()) {?>

            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
              <table class="table table-hover">
               

                <?php while ($destaque = $dest->fetch(PDO::FETCH_OBJ)) {?>
                <tr>
                  <td width="15%"><img src="uploads/imagens/<?php echo $destaque->foto ?>" alt="" style="max-height:100px; border:1px solid #ddd;"></td>
                  <td width="45%">
                    <p style="font-size: 18px;font-weight: 900"><?php echo $destaque->titulodestaque ?></p>
                    <p><?php echo $destaque->titulocategoria ?></p>
                    </td>
                  <td width="20%"></td>
                  <td width="20%">
                    <p></p>
                      <a href="#" data-toggle="modal" data-target="#modal-foto<?php echo $destaque->iddestaque ?>"><i style="margin-right:20px;" class="fas fa-camera"></i></a>
                      <a href="#" data-toggle="modal" data-target="#modal-atualizar<?php echo $destaque->iddestaque ?>"><i style="margin-right:20px;" class="fas fa-pencil-alt"></i></a>
                      <a href="destaque_admin.php?act=excluir&id=<?php echo $destaque->iddestaque ?>"><i class="fas fa-trash-alt"></i></a>
                  </td>

                </tr>

                <?php }?>

              </table>
            </div>

            <?php }?>

            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php include 'estrutura_rodape.php';?>

  <!-- ########## MODAL INSERIR ########## -->
  <div class="modal fade" id="modal-inserir">
    <div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Inserir Destaque</h4>
        </div>
        <div class="modal-body">


            <div class="row">
              <form action="destaque_admin.php?act=inserir" method="POST" enctype="multipart/form-data">

                  <div class="col-xs-12 pad">
                      <p style="font-size: 16px;"><strong>Foto Destaque</strong></p>
                      <input type="file" name="myfile" id="fileToUpload" class="form-control" required>
                  </div>

                  <div class="col-xs-12 pad">
                      <input type="text" name="titulo" class="form-control" placeholder="Titulo*" required>
                  </div>

                  <div class="col-xs-12 pad">
                      <input type="text" name="subtitulo" class="form-control" placeholder="Subtitulo">
                  </div>

                  <?php $cat = $conn->query("SELECT * FROM categorias_destaques order by idcategorias desc"); ?>

                  <div class="col-xs-12 pad">
                      <select name="categoria" class="form-control" required>
                        
                        <option value="">Selecione uma Categoria*</option>
                        
                        <?php while ($categoria = $cat->fetch(PDO::FETCH_OBJ)) {?>
                          <option value="<?php echo $categoria->idcategorias ?>"><?php echo $categoria->titulo ?></option>
                        <?php } ?> 

                      </select> 
                  </div>

                  <div class="col-xs-12 pad">
                      <input type="text" name="link" class="form-control" placeholder="Link">
                  </div>

                  <div class="col-xs-12 pad">
                      <button type="submit" value="Upload Image" name="submit" class="btn btn-primary" style="margin-top:20px;">Cadastrar</button>
                  </div>

              </form>
            </div>

        </div>
        <!-- <div class="modal-footer">
        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
        </div> -->
    </div>
    <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  <!-- /.modal -->


  <?php
    $destparamodal = $conn->query("SELECT * FROM destaque order by iddestaque desc");
    // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
    while ($destmodal = $destparamodal->fetch(PDO::FETCH_OBJ)) {
        // ######### LAÇO DE REPETIÇÃO MODAL CONFORME SELECT ANTERIOR
    ?>

    <!-- ########## MODAL ATUALIZAR ########## -->
    <div class="modal fade" id="modal-atualizar<?php echo $destmodal->iddestaque ?>">
      <div class="modal-dialog modal-lg">
      <div class="modal-content">
          <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">Editar Destaque</h4>
          </div>
          <div class="modal-body">

            <div class="row">
              <form enctype="multipart/form-data" action="destaque_admin.php?act=editar&id=<?php echo $destmodal->iddestaque ?>" method="POST">
                  
                  <div class="col-xs-12 pad">
                      <input type="text" name="titulo" class="form-control" placeholder="Titulo*" value="<?php echo $destmodal->titulo ?>" required>
                  </div>

                  <div class="col-xs-12 pad">
                      <input type="text" name="subtitulo" class="form-control" placeholder="Subtitulo" value="<?php echo $destmodal->subtitulo ?>">
                  </div>

                  <?php $cat = $conn->query("SELECT * FROM categorias_destaques order by idcategorias desc"); 

                      $idcatselect = $destmodal->id_categoria;
                  ?>

                  <div class="col-xs-12 pad">
                      <select name="categoria" class="form-control" required>
                        
                        <?php while ($categoria = $cat->fetch(PDO::FETCH_OBJ)) {?>
                          <option value="<?php echo $categoria->idcategorias ?>" <?php if($idcatselect == $categoria->idcategorias) { echo "selected"; }?>><?php echo $categoria->titulo ?></option>
                        <?php } ?> 

                      </select> 
                  </div>

                  <div class="col-xs-12 pad">
                      <input type="text" name="link" class="form-control" placeholder="Link" value="<?php echo $destmodal->link ?>">
                  </div>

                  <div class="col-xs-12 pad">
                      <button type="submit" value="Upload Image" name="submit" class="btn btn-primary" style="margin-top:20px;">Atualizar</button>
                  </div>

              </form>
            </div>

          </div>
          <!-- <div class="modal-footer">
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
          </div> -->
      </div>
      <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
  <?php }?>


  <?php
    $fotodest = $conn->query("SELECT * FROM destaque order by iddestaque desc");
    // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
    while ($destaqfoto = $fotodest->fetch(PDO::FETCH_OBJ)) {
        // ######### LAÇO DE REPETIÇÃO MODAL CONFORME SELECT ANTERIOR
    ?>

    <!-- ########## MODAL ATUALIZAR FOTO ########## -->
    <div class="modal fade" id="modal-foto<?php echo $destaqfoto->iddestaque ?>">
      <div class="modal-dialog">
      <div class="modal-content">
          <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">Atualizar foto destaque </h4>
          </div>
          <div class="modal-body">

            <div class="row">
              <form enctype="multipart/form-data" action="destaque_admin.php?act=foto&id=<?php echo $destaqfoto->iddestaque ?>" method="POST">
                  
                  <div class="col-xs-12 pad">
                      <p style="font-size: 16px;"><strong>Foto Destaque</strong></p>
                      <input type="file" name="myfile" id="fileToUpload" class="form-control" required>
                  </div>

                  <div class="col-xs-12 pad">
                      <button type="submit" value="Upload Image" name="submit" class="btn btn-primary" style="margin-top:20px;">Atualizar</button>
                  </div>

              </form>
            </div>

          </div>
          <!-- <div class="modal-footer">
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
          </div> -->
      </div>
      <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
  <?php }?>

  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- CK Editor -->
<script src="bower_components/ckeditor/ckeditor.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<script>
  $(document).ready(function () {
    $('.sidebar-menu').tree()
  })
</script>

</body>
</html>

Zerion Mini Shell 1.0