ok

Mini Shell

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

<?php

include '../conexao.php';
function generateRandomString($length = 10)
{
  $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $charactersLength = strlen($characters);
  $randomString = '';
  for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, $charactersLength - 1)];
  }
  return $randomString;
}


// ############# INSERE CATALOGOS ###################
if (isset($_GET["act"]) && $_GET["act"] == "inserir" && isset($_POST["submit"])) {
  $pag_titulo = $_POST["titulo"];
  $pag_subtitulo = $_POST["subtitulo"];
  $pag_corpo = $_POST["editor1"];
  $pag_categoria = $_POST["categoria"];



  $dados_not = array(
    'titulo' => $pag_titulo,
    'subtitulo' => $pag_subtitulo,
    'corpo' => $pag_corpo,
    'categoria' => $pag_categoria,

  );

  $conn->prepare("INSERT INTO catalogos (titulo, subtitulo, id_categoria, corpo) VALUES (:titulo, :subtitulo, :categoria, :corpo)")->execute($dados_not);


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

// ############# DELETA FOTO CATALOGOS ###################
if (isset($_GET["act"]) && $_GET["act"] == "excluirfoto") {
  $foto_exclui = $_GET["id"];

  $dados_cat = array(
    'id' => $foto_exclui,
  );

  $seleteste = $conn->query("SELECT foto FROM fotos where idfotos = " . $foto_exclui);
  $seledell = $seleteste->fetch(PDO::FETCH_OBJ);

  $filedell = "uploads/fotos/" . $seledell->foto;

  unlink($filedell);
  sleep(2);

  $conn->prepare("DELETE FROM fotos WHERE idfotos = :id")->execute($dados_cat);

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

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

  $dados_cat = array(
    'id' => $pag_exclui,
  );

  $conn->prepare("DELETE FROM catalogos WHERE idcatalogos = :id")->execute($dados_cat);

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

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

  $pag_id = $_GET["id"];

  $idinsertfck = $_GET["id"] + 1;

  $name_ckeditor = $_POST["editor" . $idinsertfck];

  $pag_titulo = $_POST["titulo"];
  $pag_subtitulo = $_POST["subtitulo"];
  $categoria_edita = $_POST["categoria"];

  $dados_titulo = array(
    'id' => $pag_id,
    'titulo' => $pag_titulo,
    'subtitulo' => $pag_subtitulo,
    'corpo' => $name_ckeditor,
    'categoria' => $categoria_edita,
  );

  $conn->prepare("UPDATE catalogos SET titulo = :titulo, subtitulo = :subtitulo, corpo = :corpo, id_categoria = :categoria WHERE idcatalogos = :id")->execute($dados_titulo);

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

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

  $pag_id = $_GET["id"];

  // ################# UPLOAD MULTIPLAS IMAGENS #############
  // Count total files
  $countfiles = count($_FILES['file']['name']);

  // Looping all files
  for ($i = 0; $i < $countfiles; $i++) {
    $filename = generateRandomString() . trim($_FILES['file']['name'][$i]);

    // Upload file
    move_uploaded_file($_FILES['file']['tmp_name'][$i], 'uploads/fotos/' . $filename);

    $dados_foto = array(
      'idcatalogo' => $pag_id,
      'imagem' => $filename,
    );

    // INSERT FOTO
    $conn->prepare("INSERT INTO fotos (foto, id_catalogo) VALUES (:imagem, :idcatalogo)")->execute($dados_foto);
  }


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

// ############# UPDATE INFO. IMAGEM ###################
if (isset($_GET["act"]) && $_GET["act"] == "infoimg") {

  $pag_id = $_GET["id"];

  $pag_titulo = $_POST["titulo"];
  $pag_subtitulo = $_POST["subtitulo"];

  $dados_titulo = array(
    'id' => $pag_id,
    'titulo' => $pag_titulo,
    'subtitulo' => $pag_subtitulo,
  );

  $conn->prepare("UPDATE fotos SET titulo = :titulo, subtitulo = :subtitulo WHERE idfotos = :id")->execute($dados_titulo);

  $redirect = "/administrador/catalogo_admin.php";
  //$redirect = "http://www.tchaudor.com.br/administrador/catalogo_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 Atrativos</p>
      </div>
      <div class="col-md-8" style="height: 34px;padding-left: 0px">
        <p style="color: #3a3a3a;font-size: 14px;">Tela Inicial/Gerenciamento Atrativos</p>
      </div>
      <div class="col-md-4" style="text-align: right;margin-bottom: 1%">
        <a href="categorias_catalogo_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</a>
      </div>
    </div>
    <div class="col-md-12" style="height: 22px">
    </div>

      <!-- Main content -->
      <section class="content">

        <?php

        $servicos = $conn->query("SELECT catalogos.idcatalogos, catalogos.titulo as titulocatalogo, categorias_catalogo.categoria as titulocat FROM catalogos inner join categorias_catalogo on catalogos.id_categoria = categorias_catalogo.idcategoria order by idcatalogos 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 Produto</a> -->
              </div>
                    <?php while ($depo = $servicos->fetch(PDO::FETCH_OBJ)) { ?>
                      <div class="col-md-4" style="padding-top: 3%;background: #fff">
                      <div class="box box-widget widget-user">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <div class="widget-user-header bg-aqua-active">
                          <h3 class="widget-user-username"> <?php echo $depo->titulocatalogo ?></h3>
                          <h5 class="widget-user-desc"><?php echo $depo->titulocat ?></h5>
                        </div>
                        <div class="widget-user-image">
                          <!-- <img class="img-circle" style="background: #ddd;height: 90px;width: 90px"  src="uploads/imagens/<?php echo $depo->foto ?>" alt="User Avatar"> -->
                        </div>
                        <div class="box-footer">
                          <div class="row">
                            <div class="col-sm-4 border-right">
                              <div class="description-block">
                                <!-- <a href="#" data-toggle="modal" data-target="#modal-inserir" class="btn btn-primary btn-flat" style="margin-right: 4%;background: #00a7d0;border-color: #00a7d0">Inserir </a> -->
                                <a href="#" data-toggle="modal" data-target="#modal-foto-att<?php echo $depo->idcatalogos ?>"><i style="margin-right:20px;" class="fas fa-camera"></i></a>
                              </div>
                              <!-- /.description-block -->
                            </div>
                            <!-- /.col -->
                            <div class="col-sm-4 border-right">
                              <div class="description-block">
                                <!-- <a href="#" data-toggle="modal" data-target="#modal-inserir" class="btn btn-primary btn-flat" style="margin-right: 4%;background: #00a7d0;border-color: #00a7d0">Inserir </a> -->
                               <a href="#" data-toggle="modal" data-target="#modal-atualizar<?php echo $depo->idcatalogos ?>"><i style="margin-right:20px;" class="fas fa-pencil-alt"></i></a>
                              </div>
                              <!-- /.description-block -->
                            </div>
                            <!-- /.col -->
                            <div class="col-sm-4">
                              <div class="description-block">
                                <!-- <a href="#" data-toggle="modal" data-target="#modal-inserir" class="btn btn-primary btn-flat" style="margin-right: 4%;background: #00a7d0;border-color: #00a7d0">Inserir</a> -->
                                 <a href="catalogo_admin.php?act=excluir&id=<?php echo $depo->idcatalogos ?>"><i class="fas fa-trash-alt"></i></a>
                             
                              </div>
                              <!-- /.description-block -->
                            </div>
                            <!-- /.col -->
                          </div>
                          <!-- /.row -->
                        </div>
                      </div>
                    </div>

                    <?php } ?>

                  
                </div>

                
                          
                         
                
              <!-- /.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</h4>
          </div>
          <div class="modal-body">


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

              
                <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_catalogo where id_pai = 0 order by idcategoria 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->idcategoria ?>"><?php echo $categoria->categoria ?></option>
                    <?php } ?>

                  </select>
                </div>

                <div class="col-xs-12 pad">
                  <textarea id="editor1" name="editor1" rows="10" cols="80"></textarea>
                </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
    $pagparamodal = $conn->query("SELECT * FROM catalogos order by idcatalogos desc");
    // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
    while ($pagmodal = $pagparamodal->fetch(PDO::FETCH_OBJ)) {
      // ######### LAÇO DE REPETIÇÃO MODAL CONFORME SELECT ANTERIOR
      ?>

      <!-- ########## MODAL ATUALIZAR ########## -->
      <div class="modal fade" id="modal-atualizar<?php echo $pagmodal->idcatalogos ?>">
        <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</h4>
            </div>
            <div class="modal-body">

              <div class="row">
                <form enctype="multipart/form-data" action="catalogo_admin.php?act=editar&id=<?php echo $pagmodal->idcatalogos ?>" method="POST">


                  <div class="col-xs-12 pad">
                    <input type="text" name="titulo" class="form-control" placeholder="Titulo*" value="<?php echo $pagmodal->titulo ?>" required>
                  </div>

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

                  <?php
                  $cat = $conn->query("SELECT * FROM categorias_catalogo where id_pai = 0 order by idcategoria desc");

                  $idcatselect = $pagmodal->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->idcategoria ?>" <?php if ($idcatselect == $categoria->idcategoria) {
                                                                                echo "selected";
                                                                              } ?>><?php echo $categoria->categoria ?></option>
                      <?php } ?>

                    </select>
                  </div>

                  <div class="col-xs-12 pad">
                    <textarea id="editor<?php echo $pagmodal->idcatalogos + 1 ?>" name="editor<?php echo $pagmodal->idcatalogos + 1 ?>" rows="10" cols="80"><?php echo $pagmodal->corpo ?></textarea>
                  </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
    $fotomodal = $conn->query("SELECT * FROM catalogos order by idcatalogos desc");
    // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
    while ($modalfoto = $fotomodal->fetch(PDO::FETCH_OBJ)) {
      // ######### LAÇO DE REPETIÇÃO MODAL CONFORME SELECT ANTERIOR
      ?>

      <!-- ########## MODAL ATUALIZAR FOTO ########## -->
      <div class="modal fade" id="modal-foto-att<?php echo $modalfoto->idcatalogos ?>">
        <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 Foto</h4>
            </div>
            <div class="modal-body">

              <div class="row">
                <form enctype="multipart/form-data" action="catalogo_admin.php?act=foto&id=<?php echo $modalfoto->idcatalogos ?>" method="POST">

                  <div class="col-xs-12 pad">
                    <p style="font-size: 16px;"><strong>Fotos </strong></p>
                    <input multiple type="file" name="file[]" id="file" style="width:88%;  float:left; margin-right: 20px;">
                    <button type="submit" value="Upload Image" name="submit" class="btn btn-primary">Atualizar</button>
                  </div>



                </form>

                <div class="col-xs-12">
                  <?php

                  $foto = $conn->query("SELECT * FROM fotos where id_catalogo = " . $modalfoto->idcatalogos);

                  if ($foto->rowCount()) {

                    ?>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                      <table class="table table-hover">
                        <tr>
                          <th width="30%">Fotos:</th>
                          <th width="60%"></th>
                          <th width="10%">Ações:</th>

                        </tr>

                        <?php while ($fotomoda = $foto->fetch(PDO::FETCH_OBJ)) { ?>
                          <tr>

                            <td width="30%">
                              <img src="uploads/fotos/<?php echo $fotomoda->foto ?>" style="max-width: 150px;">
                            </td>
                            <td width="60%"><?php echo $fotomoda->titulo ?></td>
                            <td width="10%">
                              <a href="#" data-toggle="modal" data-target="#modal-info-ftt<?php echo $fotomoda->idfotos ?>"><i style="margin-right:20px;" class="fas fa-pencil-alt"></i></a>
                              <a href="catalogo_admin.php?act=excluirfoto&id=<?php echo $fotomoda->idfotos ?>"><i class="fas fa-trash-alt"></i></a>
                            </td>

                          </tr>

                        <?php } ?>

                      </table>
                    </div>

                  <?php } ?>

                </div>
              </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
    $descimage = $conn->query("SELECT * FROM fotos where id_catalogo <> 0");
    // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
    while ($imginfo = $descimage->fetch(PDO::FETCH_OBJ)) {
      // ######### LAÇO DE REPETIÇÃO MODAL CONFORME SELECT ANTERIOR
      ?>

      <!-- ########## MODAL ATUALIZAR ########## -->
      <div class="modal fade" id="modal-info-ftt<?php echo $imginfo->idfotos ?>">
        <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 Informações da Imagem</h4>
            </div>
            <div class="modal-body">

              <div class="row">
                <form enctype="multipart/form-data" action="catalogo_admin.php?act=infoimg&id=<?php echo $imginfo->idfotos ?>" method="POST">


                  <div class="col-xs-12 pad">
                    <input type="text" name="titulo" class="form-control" 
                    <?php if ($imginfo->titulo == null) {
                      echo "placeholder=' Titulo '";
                    } else {
                      echo "value='$imginfo->titulo'";
                    } ?>>
                  </div>

                  <div class="col-xs-12 pad">
                    <input type="text" name="subtitulo" class="form-control" 
                    <?php if ($imginfo->subtitulo == null) {
                      echo "placeholder='Subtitulo'";
                    } else {
                      echo "value='$imginfo->subtitulo'";
                    } ?>>
                  </div>

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

  <script>
    $(function() {
      // Replace the <textarea id="editor1"> with a CKEditor
      // instance, using default configuration.
      CKEDITOR.replace('editor1')
      //bootstrap WYSIHTML5 - text editor
      $('.textarea').wysihtml5()
    })
  </script>

  <?php
  $scriptmodal = $conn->query("SELECT * FROM catalogos order by idcatalogos desc");
  // ##### SELECT IGUAL O DA LISTA COM MESMA ORDENAÇÃO PARA QUE TENHA O MESMO RESULTADO #######
  while ($pagscript = $scriptmodal->fetch(PDO::FETCH_OBJ)) {
    // ######### LAÇO DE REPETIÇÃO SCRIPT CKEDITOR - MODAL CONFORME SELECT ANTERIOR
    ?>
    <script>
      $(function() {
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace('editor<?php echo $pagscript->idcatalogos + 1 ?>')
        //bootstrap WYSIHTML5 - text editor
        $('.textarea').wysihtml5()
      })
    </script>
  <?php } ?>

</body>

</html>

Zerion Mini Shell 1.0