ok

Mini Shell

Direktori : /home/pequenacapitolio/www/administrador/
Upload File :
Current File : /home/pequenacapitolio/www/administrador/albuns_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 albuns (titulo, subtitulo, id_categoria, corpo) VALUES (:titulo, :subtitulo, :categoria, :corpo)")->execute($dados_not);

    
    $redirect = "/administrador/albuns_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/albuns_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/albuns_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/albuns_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 albuns WHERE idalbuns = :id")->execute($dados_cat);

    $redirect = "/administrador/albuns_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/albuns_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 albuns SET titulo = :titulo, subtitulo = :subtitulo, corpo = :corpo, id_categoria = :categoria WHERE idalbuns = :id")->execute($dados_titulo);

    $redirect = "/administrador/albuns_admin.php";
    //$redirect = "http://www.tchaudor.com.br/administrador/albuns_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']);

    echo $countfiles;

    // 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(
            'idalbuns' => $pag_id,
            'imagem' => $filename,
        );

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


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

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

                <?php

                $servicos = $conn->query("SELECT albuns.idalbuns, albuns.titulo as tituloalbum, categorias_albuns.titulo as titulocat FROM albuns inner join categorias_albuns on albuns.id_categoria = categorias_albuns.idcategorias order by idalbuns 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 Álbum</a> -->
                            </div>

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

                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                        <tr>
                                            <th width="6%"></th>
                                            <th width="60%">Título</th>
                                            <th width="20%">Categoria</th>
                                            <th width="15%"></th>
                                        </tr>

                                        <?php while ($depo = $servicos->fetch(PDO::FETCH_OBJ)) { ?>
                                             <tr>
                                              <td width="6%"><a href="#" data-toggle="modal" data-target="#modal-foto-att<?php echo $depo->idalbuns ?>"><i style="margin-right:20px;" class="fas fa-camera"></i></a></td> 
                                              <td width="50%"><?php echo $depo->tituloalbum ?></td>
                                              <td width="20%"><?php echo $depo->titulocat ?></td>
                                              <td width="30%">
                                                   <a href="#" data-toggle="modal" data-target="#modal-atualizar<?php echo $depo->idalbuns ?>"><i style="margin-right:20px;" class="fas fa-pencil-alt"></i></a>
                                                  <a href="albuns_admin.php?act=excluir&id=<?php echo $depo->idalbuns ?>"><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 Álbum</h4>
                    </div>
                    <div class="modal-body">


                        <div class="row">
                            <form action="albuns_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_albuns 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">
                                    <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 albuns order by idalbuns 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->idalbuns ?>">
                <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 Álbun</h4>
                        </div>
                        <div class="modal-body">

                            <div class="row">
                                <form enctype="multipart/form-data" action="albuns_admin.php?act=editar&id=<?php echo $pagmodal->idalbuns ?>" 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_albuns order by idcategorias 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->idcategorias ?>" <?php if ($idcatselect == $categoria->idcategorias) {
                                                                                                            echo "selected";
                                                                                                        } ?>><?php echo $categoria->titulo ?></option>
                                            <?php } ?>

                                        </select>
                                    </div>

                                    <div class="col-xs-12 pad">
                                        <textarea id="editor<?php echo $pagmodal->idalbuns + 1 ?>" name="editor<?php echo $pagmodal->idalbuns + 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;">Editar</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 albuns order by idalbuns 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->idalbuns ?>">
                <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="albuns_admin.php?act=foto&id=<?php echo $modalfoto->idalbuns ?>" method="POST">

                                    <div class="col-xs-12 pad">
                                        <p style="font-size: 16px;"><strong>Fotos Álbun</strong></p>
                                        <input multiple type="file" name="file[]" id="file" style="width:60%;  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_albuns = " . $modalfoto->idalbuns);

                                    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="50%"><?php echo $fotomoda->titulo ?></td>
                                                        <td width="20%">
                                                            <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="albuns_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_albuns <> 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="albuns_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 albuns order by idalbuns 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->idalbuns + 1 ?>')
                //bootstrap WYSIHTML5 - text editor
                $('.textarea').wysihtml5()
            })
        </script>
    <?php } ?>

</body>

</html>

Zerion Mini Shell 1.0