ok
Direktori : /home/pequenacapitolio/www/administrador/ |
Current File : /home/pequenacapitolio/www/administrador/noticias_admin.php |
<?php $config['authentication'] = function() { return true; }; include '../conexao.php'; // ############# INSERE NOTICIA ################### if (isset($_GET["act"]) && $_GET["act"] == "inserir" && isset($_POST["submit"])) { $pag_titulo = $_POST["titulo"]; $pag_subtitulo = $_POST["subtitulo"]; $pag_autor = $_POST["autor"]; $pag_categoria = $_POST["categoria"]; $pag_data = $_POST["data"]; $pag_corpo = $_POST["editor1"]; $dados_not = array( 'titulo' => $pag_titulo, 'subtitulo' => $pag_subtitulo, 'autor' => $pag_autor, 'datanot' => $pag_data, 'corpo' => $pag_corpo, 'categoria' => $pag_categoria, ); $conn->prepare("INSERT INTO noticias (titulo, subtitulo, autor, data_noticia, corpo, id_categoria) VALUES (:titulo, :subtitulo, :autor, :datanot, :corpo, :categoria)")->execute($dados_not); $redirect = "/administrador/noticias_admin.php"; //$redirect = "http://www.tchaudor.com.br/administrador/noticias_admin.php"; header("location:$redirect"); } // ############# DELETA NOTICIA ################### if (isset($_GET["act"]) && $_GET["act"] == "excluir") { $pag_exclui = $_GET["id"]; $dados_cat = array( 'id' => $pag_exclui, ); $conn->prepare("DELETE FROM noticias WHERE idnoticias = :id")->execute($dados_cat); $redirect = "/administrador/noticias_admin.php"; //$redirect = "http://www.tchaudor.com.br/administrador/noticias_admin.php"; header("location:$redirect"); } // ############# UPDATE NOTICIAS ################### 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"]; $pag_autor = $_POST["autor"]; $pag_data = $_POST["data"]; $pag_corpo = $name_ckeditor; $categoria_edita = $_POST["categoria"]; $dados_titulo = array( 'id' => $pag_id, 'titulo' => $pag_titulo, 'subtitulo' => $pag_subtitulo, 'autor' => $pag_autor, 'datanot' => $pag_data, 'corpo' => $pag_corpo, 'categoria' => $categoria_edita, ); $conn->prepare("UPDATE noticias SET titulo = :titulo, subtitulo = :subtitulo, autor = :autor, data_noticia = :datanot, corpo = :corpo, id_categoria = :categoria WHERE idnoticias = :id")->execute($dados_titulo); $redirect = "/administrador/noticias_admin.php"; //$redirect = "http://www.tchaudor.com.br/administrador/noticias_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 noticias SET foto = :foto WHERE idnoticias = :id")->execute($dados_titulo); $redirect = "/administrador/noticias_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 Publicações</p> </div> <div class="col-md-6" style="height: 34px;padding-left: 0px"> <p style="color: #3a3a3a;font-size: 14px;">Tela Inicial/Gerenciamento de Publicações</p> </div> <div class="col-md-6" style="text-align: right;margin-bottom: 1%"> <a href="categorias_noticias_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" style="margin-right: 4%">Inserir Publicação</a> <!-- <a href="#" data-toggle="modal" data-target="#modal-imgserver" class="btn btn-primary btn-flat" >Eviar Fotos ao Servidor</a> --> </div> </div> <div class="col-md-12" style="height: 22px"> </div> <!-- Main content --> <section class="content"> <?php $not = $conn->query("SELECT noticias.data_noticia, noticias.idnoticias, noticias.titulo as titulonot, noticias.foto, categorias_noticias.titulo as titulocat FROM noticias inner join categorias_noticias on noticias.id_categoria = categorias_noticias.idcategorias order by idnoticias 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 Notícia</a> --> </div> <?php if ($not->rowCount()) {?> <!-- /.box-header --> <div class="box-body table-responsive no-padding"> <table class="table table-hover"> <!-- <tr> <th width="15%">Foto:</th> <th width="45%">Títilo da Publicação:</th> <th width="20%">Categoria:</th> <th width="20%">Ações:</th> </tr> --> <?php while ($noticias = $not->fetch(PDO::FETCH_OBJ)) {?> <tr> <td width="15%"><img src="uploads/imagens/<?php echo $noticias->foto ?>" alt="" style="max-height:100px; border:1px solid #ddd;"></td> <td width="45%"> <p style="font-size: 18px;font-weight: 900"><?php echo $noticias->titulonot ?></p> <p><?php echo $noticias->titulocat ?></p> </td> <td width="10%"></td> <td width="20%"> <p style="font-size: 15px;font-weight: 700">Publicado em <?php echo $noticias->data_noticia ?></p> <a href="#" data-toggle="modal" data-target="#modal-foto<?php echo $noticias->idnoticias ?>"><i style="margin-right:20px;margin-left: 30px" class="fas fa-camera"></i></a> <a href="#" data-toggle="modal" data-target="#modal-atualizar<?php echo $noticias->idnoticias ?>"><i style="margin-right:20px;" class="fas fa-pencil-alt"></i></a> <a href="noticias_admin.php?act=excluir&id=<?php echo $noticias->idnoticias ?>"><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">×</span></button> <h4 class="modal-title">Inserir Publicação</h4> </div> <div class="modal-body"> <div class="row"> <form action="noticias_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_noticias 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="autor" class="form-control" placeholder="Autor"> </div> <div class="col-xs-12 pad"> <input type="text" name="data" class="form-control" placeholder="00/00/0000" > </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 noticias order by idnoticias 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->idnoticias ?>"> <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">×</span></button> <h4 class="modal-title">Editar Publicação</h4> </div> <div class="modal-body"> <div class="row"> <form enctype="multipart/form-data" action="noticias_admin.php?act=editar&id=<?php echo $pagmodal->idnoticias ?>" 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> <div class="col-xs-12 pad"> <input type="text" name="autor" class="form-control" placeholder="Autor" value="<?php echo $pagmodal->autor ?>"> </div> <?php $cat = $conn->query("SELECT * FROM categorias_noticias 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"> <input type="text" name="data" class="form-control" placeholder="00/00/0000" value="<?php echo $pagmodal->data_noticia ?>" > </div> <div class="col-xs-12 pad"> <textarea id="editor<?php echo $pagmodal->idnoticias+1 ?>" name="editor<?php echo $pagmodal->idnoticias+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 noticias order by idnoticias 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<?php echo $modalfoto->idnoticias ?>"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="reloadPage();"> <span aria-hidden="true">×</span></button> <h4 class="modal-title">Foto Publicação</h4> </div> <div class="modal-body"> <div class="row"> <form enctype="multipart/form-data" action="noticias_admin.php?act=foto&id=<?php echo $modalfoto->idnoticias ?>" method="POST"> <div class="col-xs-12 pad"> <p style="font-size: 16px;"><strong>Foto</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;">Salvar</button> </div> </form> </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> </div> <!-- /.modal --> <?php }?> <!-- ########## MODAL ATUALIZAR FOTO ########## --> <div class="modal fade" id="modal-foto<?php echo $modalfoto->idnoticias ?>"> <div class="modal-dialog modal-lg"> <style> .in{ padding-left: 0px !important; } </style> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="reloadPage();"> <span aria-hidden="true">×</span></button> <h4 class="modal-title">Foto Publicação</h4> </div> <div class="modal-body"> <div class="row"> <iframe style="width:100%; height: 80vh;" src="/administrador/upload-imagens.php?idpag=<?php echo $modalfoto->idnoticias ?>&idcomando=2&tipo=noticias&idconsulta=idnoticias" frameborder="0"></iframe> </div> <!-- no link acima - idpag = é o id do item - idcomando = é o id do comando de update a ser aplicado - tipo = nome da respectiva tabela no banco de dados - idconsulta = nome do campo id do item --> </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 --> <!-- 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') CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl: 'bower_components/ckfinder/ckfinder.html', filebrowserUploadUrl: 'bower_components/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files', filebrowserImageBrowseUrl : 'bower_components/ckfinder/ckfinder.html?type=Images', filebrowserFlashBrowseUrl : 'bower_components/ckfinder/ckfinder.html?type=Flash', filebrowserImageUploadUrl : 'bower_components/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images', filebrowserFlashUploadUrl : 'bower_components/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash', filebrowserWindowWidth: '1000', filebrowserWindowHeight: '700' } ); //bootstrap WYSIHTML5 - text editor $('.textarea').wysihtml5() }) </script> <?php $scriptmodal = $conn->query("SELECT noticias.idnoticias, noticias.titulo as titulonoticias, noticias.id_categoria, noticias.subtitulo, noticias.corpo, categorias_noticias.titulo as titulocategoria FROM noticias inner join categorias_noticias on noticias.id_categoria = categorias_noticias.idcategorias order by idnoticias 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->idnoticias+1 ?>') //bootstrap WYSIHTML5 - text editor $('.textarea').wysihtml5() }) </script> <?php }?> </script> <script type="text/javascript"> function reloadPage(){ location.reload(true); } </script> <?php $scriptmodal = $conn->query("SELECT * FROM noticias order by idnoticias 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 ?> <?php }?> </body> </html>