├── .gitattributes ├── .DS_Store ├── pags ├── nchat.php ├── sair.php ├── inicio.php ├── login.php ├── cadastro.php ├── chat.php └── configs.php ├── lib ├── includes.php ├── dbconnect.php └── class.php ├── images ├── status-online.png ├── uploadssexta.jpg └── uploadsnophoto-ce9ebfea85cbfbb4fd42fc2915d12fca8518a1535318fb75d71426ccd3d81e4a.png ├── sys ├── send_msg.php ├── get_onlines.php ├── get_chats.php └── get_chat.php ├── .htaccess ├── README.md ├── index.php ├── js └── script.js ├── css └── style.css ├── banco de dados └── teste.sql └── LICENSE.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsalesproductions/SISTEMA-DE-CHAT-2019/HEAD/.DS_Store -------------------------------------------------------------------------------- /pags/nchat.php: -------------------------------------------------------------------------------- 1 | verifica_chat($explode['1']); 4 | ?> -------------------------------------------------------------------------------- /lib/includes.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/status-online.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsalesproductions/SISTEMA-DE-CHAT-2019/HEAD/images/status-online.png -------------------------------------------------------------------------------- /images/uploadssexta.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsalesproductions/SISTEMA-DE-CHAT-2019/HEAD/images/uploadssexta.jpg -------------------------------------------------------------------------------- /sys/send_msg.php: -------------------------------------------------------------------------------- 1 | insere_mensagem(); 5 | ?> -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | RewriteCond %{SCRIPT_FILENAME} !-f 3 | RewriteCOND %{SCRIPT_FILENAME} !-d 4 | RewriteRule ^(.*)$ index.php?pagina=$1 -------------------------------------------------------------------------------- /sys/get_onlines.php: -------------------------------------------------------------------------------- 1 | get_onlines($_GET['sexo']); 5 | ?> 6 | 7 | -------------------------------------------------------------------------------- /pags/sair.php: -------------------------------------------------------------------------------- 1 | redirect('login'); 5 | $chat->alerta('success', 'deslogando...', false); 6 | ?> -------------------------------------------------------------------------------- /sys/get_chats.php: -------------------------------------------------------------------------------- 1 | pega_chats($usuario); 6 | ?> 7 | 8 | -------------------------------------------------------------------------------- /images/uploadsnophoto-ce9ebfea85cbfbb4fd42fc2915d12fca8518a1535318fb75d71426ccd3d81e4a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tsalesproductions/SISTEMA-DE-CHAT-2019/HEAD/images/uploadsnophoto-ce9ebfea85cbfbb4fd42fc2915d12fca8518a1535318fb75d71426ccd3d81e4a.png -------------------------------------------------------------------------------- /pags/inicio.php: -------------------------------------------------------------------------------- 1 |
2 | 7 | 8 | 9 | 10 |
11 | 12 |
13 |
-------------------------------------------------------------------------------- /lib/dbconnect.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 9 | }catch(PDOException $e){ 10 | echo "Erro ao conectar-se: ".$e->getMessage(); 11 | } 12 | ?> -------------------------------------------------------------------------------- /pags/login.php: -------------------------------------------------------------------------------- 1 | verifica_logado();?> 2 |
3 |
4 |
5 |

6 | 7 |

8 | 9 | 10 | 11 |

12 | 13 |
14 |
15 | 16 |
17 | login();?> 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SISTEMA-DE-CHAT-2019 2 | Estou trazendo um projeto que fiz de um sistema de chat utilizando php, ajax e pdo. 3 | Sistema totalmente funcional para chats em real time; 4 | 5 | 6 | # Como configurar? 7 | 1º após baixar o projeto, abra o index.php, e procure por
8 | < base href="http://192.168.0.100/chat/"> ou localize a linha número 13 e troque o ### http://192.168.0.100/chat/ ### pelo url do seu site
9 | 10 |
11 | 12 | 13 | 14 |
15 | 16 | 2º Importar o banco de dados teste.sql localizado na pasta banco de dados;
17 | 18 | 3º Acessar o diretório lib/dbconnect.php e trocar os dados do banco atual para o seu;
19 | 20 | Após isso, seja feliz :) 21 | 22 |
USE A VONTADE!
23 | Para mais informações e sobre updates acesse: http://tutoriaiseinformatica.com/blog/p/sistema-de-chat-2019 24 | -------------------------------------------------------------------------------- /pags/cadastro.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Cadastre-se

4 |

Cadastre-se para conhecer e conversar com pessoas

5 |
6 |
7 |

8 |

9 |

10 |

11 |

12 | 16 |

17 |

18 | 19 | 20 |

21 | cadastro();?> 22 |
23 | 24 |
-------------------------------------------------------------------------------- /pags/chat.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |
"> dados_user($this->verifica_nomes_chat($explode['1']),"nome")?> 4 |
5 |
6 | 7 |
8 | 9 | 10 |
11 | 12 | 13 |
14 |
15 | 16 |
17 |
18 |
19 | 20 | 21 | 22 | 23 |
24 | atualiza_lido($explode['1']); 26 | //$chat->form_mensagem(); 27 | ?> 28 |
29 |
-------------------------------------------------------------------------------- /sys/get_chat.php: -------------------------------------------------------------------------------- 1 | prepare("SELECT * FROM mensagens WHERE id_chat = :id_chat ORDER BY id ASC"); 6 | $stmt->execute(array(':id_chat' => $_GET['id'])); 7 | 8 | $chat = new chat($pdo); 9 | 10 | 11 | while($dados = $stmt->fetch(PDO::FETCH_ASSOC)){ 12 | $lido = null; 13 | switch($dados['lido']){ 14 | case 0: 15 | $lido = ""; 16 | break; 17 | 18 | 19 | case 1: 20 | $lido = ""; 21 | break; 22 | } 23 | if($dados['id_de'] != $_SESSION['usuario']){ 24 | 25 | echo "
26 |
sunil
27 |
28 |
29 |

{$dados['mensagem']}

30 | {$chat->diferencia_datas($dados['data'])}
31 |
32 |
"; 33 | }else{ 34 | echo "
35 |
36 |

{$dados['mensagem']}

37 | {$lido} {$chat->diferencia_datas($dados['data'])}
38 |
"; 39 | }} 40 | 41 | }catch(PDOException $e){ 42 | echo $e->getmessage(); 43 | } 44 | 45 | ?> 46 | 47 | -------------------------------------------------------------------------------- /pags/configs.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |

Editar dados

4 |
5 | 6 |
7 |

8 | 9 | 10 |

11 | 12 |

13 | 14 | 15 |

16 | 17 |

18 | 19 | 20 |

21 | 22 |

23 | 24 | 25 |

26 | 27 |

28 | 29 | 30 | 31 | 32 |

33 | 34 |

35 | dados_user($this->usuario, 'sexo')){ 38 | case 0: 39 | $sexoAtual = ""; 40 | break; 41 | 42 | case 1: 43 | $sexoAtual = ""; 44 | break; 45 | } 46 | ?> 47 | 48 | 53 |

54 | 55 |

56 | 57 |
58 | editar_dados();?> 59 |
-------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | Sistema de chat 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
31 |
32 | dados_user($_SESSION['usuario'],'nome');?> 33 |
34 | 35 | 36 | 37 |
38 |
39 | 50 | 51 |
52 |
53 |
54 |
update_class();?>> 55 | paginacao($pdo);?> 56 |
57 |
58 | 59 | -------------------------------------------------------------------------------- /js/script.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | comeca(); 3 | send_msg(); 4 | change_busca_user(); 5 | 6 | }) 7 | 8 | var timerI = null; 9 | var timerR = false; 10 | 11 | function para(){ 12 | if(timerR) 13 | clearTimeout(timerI); 14 | timerR = false; 15 | } 16 | 17 | function comeca(){ 18 | para(); 19 | lista(); 20 | lista_chats(); 21 | lista_onlines(); 22 | } 23 | 24 | function lista(){ 25 | var id = $("#id_post").val(); 26 | $.ajax({ 27 | url:"sys/get_chat.php?id="+id, 28 | success: function(textStatus){ 29 | $("#mensagens").html(textStatus); //Mostra o resultado da página lista.php 30 | scrollBottomJQuery(); 31 | } 32 | }) 33 | timerI = setTimeout("lista()", 3000); //Tempo de espera para atualizar novamente 34 | timerR = true; 35 | } 36 | 37 | function lista_chats(){ 38 | var id = $("#id_post").val(); 39 | $.ajax({ 40 | url:"sys/get_chats.php?atual="+id, 41 | crossDomain: true, 42 | success: function(textStatus){ 43 | $("#chats").html(textStatus); //Mostra o resultado da página lista.php 44 | } 45 | }) 46 | timerI = setTimeout("lista_chats()", 3000); //Tempo de espera para atualizar novamente 47 | timerR = true; 48 | } 49 | 50 | function lista_onlines(){ 51 | var id = $("#busca-por").val(); 52 | $.ajax({ 53 | url:"sys/get_onlines.php?sexo="+id, 54 | crossDomain: true, 55 | success: function(textStatus){ 56 | $("#users").html(textStatus); //Mostra o resultado da página lista.php 57 | } 58 | }) 59 | timerI = setTimeout("lista_onlines()", 3000); //Tempo de espera para atualizar novamente 60 | timerR = true; 61 | } 62 | 63 | function change_busca_user(){ 64 | $("#busca-por").change(function() { 65 | lista_onlines(); 66 | }); 67 | } 68 | 69 | function send_msg(){ 70 | $("#sendmsg").on("submit", function(e){ 71 | var id = $("#id_post").val(); 72 | e.preventDefault(); 73 | var form = $(this); 74 | 75 | $.ajax({ 76 | type: "post", 77 | url: "sys/send_msg.php?atual="+id, 78 | data: form.serialize(), 79 | dataType: "json", 80 | success: function(data){ 81 | lista(); 82 | $("#msg").val(""); 83 | },error: function (jqXHR, exception) { 84 | alert(jqXHR.responseText); 85 | } 86 | }); 87 | }); 88 | } 89 | 90 | function show_bar(){ 91 | $("#left-menu").show(); 92 | } 93 | 94 | //essa versao usando o jquery 95 | function scrollBottomJQuery(){ 96 | $("#msghistory").scrollTop($("#msghistory")[0].scrollHeight); 97 | } 98 | 99 | function vefifica_mobile(){ 100 | if( navigator.userAgent.match(/Android/i) 101 | || navigator.userAgent.match(/webOS/i) 102 | || navigator.userAgent.match(/iPhone/i) 103 | || navigator.userAgent.match(/iPad/i) 104 | || navigator.userAgent.match(/iPod/i) 105 | || navigator.userAgent.match(/BlackBerry/i) 106 | || navigator.userAgent.match(/Windows Phone/i)){ 107 | return true; 108 | } 109 | else { 110 | return false; 111 | } 112 | } 113 | 114 | function verifica_status(){ 115 | if(vefifica_mobile() == true){ 116 | seta_status(true); 117 | } 118 | } 119 | 120 | function seta_status(status){ 121 | if(status == true && vefifica_mobile() == true){ 122 | $("#left-menu").hide(); 123 | }else{ 124 | $("#left-menu").show(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Roboto&display=swap'); 2 | body{margin: 2% 2% 2% 2%; font-family: 'Roboto', sans-serif; background-color: limegreen} 3 | .container{max-width:100%; margin:auto;} 4 | 5 | img{max-width:100%;} 6 | .inbox_people {background: #f8f8f8 none repeat scroll 0 0;float: left;overflow: hidden;width: 40%; border-right:1px solid #c4c4c4;} 7 | .inbox_msg {border: 1px solid #c4c4c4;clear: both;overflow: hidden;} 8 | .top_spac{ margin: 20px 0 0;} 9 | .recent_heading {float: left; width:40%;} 10 | .srch_bar {width: 100%;} 11 | .headind_srch{ padding:10px 0px 10px 0px; overflow:hidden; /*border-bottom:1px solid #c4c4c4;*/} 12 | .recent_heading h4 {color: #CCC ;font-size: 21px;margin: auto;} 13 | .srch_bar input{ border:1px solid #cdcdcd; border-width:0 0 0px 0; width:90%; padding:10px 0 4px 10px; background:#314659; color: #EEE;} 14 | .srch_bar input::placeholder{color: #CCC;} 15 | .srch_bar input:focus{border:0;outline:none;box-shadow:none;} 16 | .srch_bar .input-group-addon button {background: rgba(0, 0, 0, 0); none repeat scroll 0 0;border: medium none;padding: 0;color: #707070;font-size: 18px;} 17 | .srch_bar .input-group-addon button:focus{border:0;outline:none;box-shadow:none;} 18 | .srch_bar .fa-search{color: #CCC;} 19 | .srch_bar .input-group-addon { margin: 0 0 0 -27px;} 20 | 21 | 22 | .chat_ib h5{ font-size:15px; color:#464646; margin:0 0 8px 0;} 23 | .chat_ib h5 a{text-decoration: none; color:#464646;} 24 | .chat_ib h5 a:hover{text-decoration: none;} 25 | .chat_ib h5 span{ font-size:13px; float:right;} 26 | .chat_ib p{ font-size:14px; color:#989898; margin:auto} 27 | .chat_img {float: left;width: 11%;} 28 | .chat_ib {float: left;padding: 0 0 0 15px;width: 88%;} 29 | 30 | .chat_people{ overflow:hidden; clear:both;} 31 | .chat_people .chat_img img{border-radius: 50px;} 32 | .chat_list {/*border-bottom: 1px solid #c4c4c4;*/margin: 0;padding: 18px 16px 10px;} 33 | .inbox_chat { height: 550px; overflow-y: auto;} 34 | .inbox_chat::-webkit-scrollbar-track{-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);} 35 | .inbox_chat::-webkit-scrollbar{width: 6px;} 36 | .inbox_chat::-webkit-scrollbar-thumb{ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);} 37 | .active_chat{ background:#304759; border-right: 4px solid rgba(255,255,255,.1);} 38 | 39 | .incoming_msg_img {display: inline-block;width: 6%;} 40 | .received_msg {display: inline-block;padding: 0 0 0 10px;vertical-align: top;width: 92%;} 41 | .received_withd_msg p {background: #3F5668 none repeat scroll 0 0;border-radius: 3px;color: #CCC;font-size: 14px;margin: 0;padding: 5px 10px 5px 12px;width: 100%;} 42 | .time_date {color: #747474;display: block;font-size: 12px;margin: 8px 0 0;} 43 | .received_withd_msg { width: 57%;} 44 | .mesgs {float: left;padding: 30px 15px 0 25px;width: 60%;} 45 | 46 | .sent_msg p {background: #F8F7F5 none repeat scroll 0 0;border-radius: 3px;font-size: 14px;margin: 0; color:#333;padding: 5px 10px 5px 12px;width:100%;} 47 | .outgoing_msg{ overflow:hidden; margin:26px 0 26px;} 48 | .sent_msg {float: right;width: 46%;} 49 | .input_msg_write input {background: #FFF none repeat scroll 0 0;border: medium none;color: #4c4c4c;font-size: 15px;min-height: 48px;width: 100%;padding-left: 20px;} 50 | .input_msg_write input:focus{border:0;outline:none;box-shadow:none;} 51 | 52 | .type_msg {border-top: 1px solid #c4c4c4;position: relative;} 53 | .msg_send_btn {background: #05728f none repeat scroll 0 0;border: medium none;border-radius: 50%;color: #fff;cursor: pointer;font-size: 17px;height: 33px;position: absolute;right: 0;top: 11px;width: 33px; margin-right: 5px;} 54 | .messaging { padding: 0 0 50px 0;} 55 | .msg_history {height: 610px;overflow-y: auto;} 56 | .msg_history::-webkit-scrollbar-track{-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);} 57 | .msg_history::-webkit-scrollbar{width: 6px;} 58 | .msg_history::-webkit-scrollbar-thumb{ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);} 59 | .fa-check-double{color: dodgerblue;} 60 | 61 | 62 | .login{box-shadow: 10px 10px 5px #528D3F; background: #FFF; padding: 40px;} 63 | .login .login-title{background-color: dodgerblue; color: #FFF; padding: 20px; font-size: 20px; margin-bottom: 10px;} 64 | .login .login-content{padding: 10px;} 65 | .login .login-content .form-control{border-radius: 0px; height: 45px; background-color: #f2f2f2; border:none; color: #bababa; } 66 | .login .login-content .form-control::placeholder{color: #bababa;} 67 | .login .login-content .form-control:focus{border:0;outline:none;box-shadow:none;} 68 | .login .login-content .btn{border-radius: 0px;} 69 | 70 | .row{margin: 0px; padding: 0px;} 71 | .col-sm-4{/*border: 1px solid #c4c4c4;*/clear: both;overflow: hidden; padding: 0px;} 72 | .col-sm-8{/*border: 1px solid #c4c4c4;*/clear: both;overflow: hidden; padding: 0px 0px 0px 0px;background-color: #FFF} 73 | .msg_history{padding: 0px 10px 10px 10px; background-color: #E6EAEB;} 74 | .inbox_peoplen {background-color: #2D3E50; overflow: hidden; /*border-right:1px solid #c4c4c4;*/;} 75 | .inbox_chat{background-color: #2D3E50;} 76 | .inbox_chat .name-user{color: #CCC;} 77 | .inbox_chat .chat_date{color: #CCC;} 78 | .inbox_chat p{color: #CCC;} 79 | .user_infos{background-color: #2D3E50; padding: 20px;} 80 | .user_infos img{width: 70px; border-radius: 50px;} 81 | .online{border: 2px solid limegreen;} 82 | .user_infos span{ font-size: 20px; color: #CCC; margin-left: 2%;} 83 | .title-chat{background-color: #f5f5f5; padding: 0px; margin: 0px;} 84 | .title-chat .u-info{padding: 5px 10px 5px 10px; margin: 0px; border-bottom: 1px solid #ccc;} 85 | .title-chat .u-info img{width: 50px;} 86 | .alert{border-radius: 0px;} 87 | .fa-chevron-left{padding-right: 10px; color: gray} 88 | .fa-chevron-left:hover{color: #000;} 89 | .nlink{color: #ccc;} 90 | .nlink:hover{color: #ccc;} 91 | .inicio-content .form-control{border-radius: 0px;} 92 | 93 | .users .user{display: inline-block; width: 18%; text-align: center; font-size: 14px;} 94 | .users .user .img-user{width: 120px;} 95 | .users .user{margin-top: 10px;} 96 | .users .user a{text-decoration: none; color: #000;} 97 | .infos-login{text-align: right} 98 | .infos-login a{text-decoration: none; color: #000;} 99 | .cadastro-form{color: #333; padding: 20px; box-shadow: 10px 10px 5px #528D3F; border: 1px solid #ccc;} 100 | .cadastro-form .form-control{border-radius: 0px;} 101 | .cadastro-form .btn{border-radius: 0px;} 102 | .cadastro-form .form-control:focus{outline:none;box-shadow:none;} 103 | .edit-dados{margin: 20px;} 104 | .edit-dados .form-control{border-radius: 0px;} 105 | .edit-dados .btn{border-radius: 0px;} 106 | 107 | 108 | @media (min-width:992px) {/*DESKTOP*/ 109 | #backbtn{display: none;} 110 | 111 | } 112 | 113 | @media (max-width:992px) {/*MOBILE*/ 114 | .users .user{margin: 10px;} 115 | } -------------------------------------------------------------------------------- /banco de dados/teste.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.8.5 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: 29-Maio-2019 às 23:21 7 | -- Versão do servidor: 10.1.38-MariaDB 8 | -- versão do PHP: 7.3.4 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET AUTOCOMMIT = 0; 12 | START TRANSACTION; 13 | SET time_zone = "+00:00"; 14 | 15 | 16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 19 | /*!40101 SET NAMES utf8mb4 */; 20 | 21 | -- 22 | -- Database: `teste` 23 | -- 24 | 25 | -- -------------------------------------------------------- 26 | 27 | -- 28 | -- Estrutura da tabela `chats` 29 | -- 30 | 31 | CREATE TABLE `chats` ( 32 | `id` int(20) NOT NULL, 33 | `id_de` varchar(200) NOT NULL, 34 | `id_para` varchar(200) NOT NULL, 35 | `lastupdate` varchar(200) NOT NULL 36 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 37 | 38 | -- 39 | -- Extraindo dados da tabela `chats` 40 | -- 41 | 42 | INSERT INTO `chats` (`id`, `id_de`, `id_para`, `lastupdate`) VALUES 43 | (5, 'thsales061', 'rafael065', '23-05-2019 13:39:35'), 44 | (6, 'thsales061', 'isa232', '25-05-2019 13:10:55'), 45 | (8, 'rafael065', 'isa232', '25-05-2019 13:03:59'); 46 | 47 | -- -------------------------------------------------------- 48 | 49 | -- 50 | -- Estrutura da tabela `mensagens` 51 | -- 52 | 53 | CREATE TABLE `mensagens` ( 54 | `id` int(11) NOT NULL, 55 | `id_de` varchar(200) NOT NULL, 56 | `id_chat` int(11) NOT NULL, 57 | `mensagem` text NOT NULL, 58 | `data` varchar(200) NOT NULL, 59 | `lido` int(11) NOT NULL DEFAULT '0' 60 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 61 | 62 | -- 63 | -- Extraindo dados da tabela `mensagens` 64 | -- 65 | 66 | INSERT INTO `mensagens` (`id`, `id_de`, `id_chat`, `mensagem`, `data`, `lido`) VALUES 67 | (1, 'thsales061', 5, 'Eai, tudo bem?', '18-05-2019 14:07:10', 1), 68 | (2, 'rafael065', 5, 'Eai... Sim, e você?', '18-05-2019 14:08:10', 1), 69 | (5, 'thsales061', 6, 'Oi', '18-05-2019 14:09:10', 1), 70 | (6, 'isa232', 6, 'Oiii', '18-05-2019 14:10:10', 1), 71 | (7, 'thsales061', 5, 'dasdsad', '18-05-2019 14:46:10', 1), 72 | (8, 'thsales061', 5, 'dasdas', '18-05-2019 14:46:10', 1), 73 | (9, 'thsales061', 5, 'dasdas', '18-05-2019 14:46:10', 1), 74 | (10, 'thsales061', 5, 'dsfdsf', '18-05-2019 14:46:10', 1), 75 | (11, 'thsales061', 5, 'dsadsad', '21-05-2019 09:56:10', 1), 76 | (12, 'thsales061', 5, 'dsadsad', '21-05-2019 09:56:10', 1), 77 | (13, 'thsales061', 5, 'dsadasd', '21-05-2019 09:56:10', 1), 78 | (14, 'thsales061', 5, 'dsadasd', '21-05-2019 09:56:10', 1), 79 | (15, 'thsales061', 5, 'dsadsad', '21-05-2019 09:56:10', 1), 80 | (16, 'thsales061', 5, 'dsadasd', '21-05-2019 09:56:10', 1), 81 | (17, 'thsales061', 5, 'teste', '21-05-2019 11:57:27', 1), 82 | (18, 'thsales061', 5, 'dsadsad', '21-05-2019 12:06:21', 1), 83 | (19, 'thsales061', 5, 'dsadsad', '21-05-2019 12:14:34', 1), 84 | (20, 'thsales061', 5, 'sobe', '21-05-2019 12:15:37', 1), 85 | (21, 'thsales061', 6, 'Tudo bem?', '21-05-2019 12:16:03', 1), 86 | (22, 'rafael065', 5, 'Eai', '21-05-2019 14:37:04', 1), 87 | (23, 'thsales061', 5, 'Eai, tudo bem?', '21-05-2019 14:37:22', 1), 88 | (24, 'rafael065', 5, 'beleza, e você?', '21-05-2019 14:37:30', 1), 89 | (25, 'thsales061', 5, 'De boa...', '21-05-2019 14:37:33', 1), 90 | (26, 'rafael065', 5, 'Que bom', '21-05-2019 14:37:39', 1), 91 | (27, 'thsales061', 5, 'Sim :)', '21-05-2019 14:37:44', 1), 92 | (28, 'rafael065', 5, 'Legal', '21-05-2019 14:38:22', 1), 93 | (29, 'thsales061', 5, 'dasd', '21-05-2019 14:38:27', 1), 94 | (30, 'rafael065', 5, 'haha', '21-05-2019 14:39:53', 1), 95 | (31, 'thsales061', 5, 'dasdasd', '21-05-2019 14:40:03', 1), 96 | (32, 'rafael065', 5, 'Haha', '21-05-2019 14:44:50', 1), 97 | (33, 'rafael065', 5, 'Legal...', '21-05-2019 14:44:58', 1), 98 | (34, 'thsales061', 6, '......', '22-05-2019 14:25:58', 1), 99 | (35, 'thsales061', 6, '.....', '22-05-2019 14:26:11', 1), 100 | (36, 'thsales061', 6, 'dsadsad', '22-05-2019 15:18:11', 1), 101 | (37, 'rafael065', 5, 'Eai', '22-05-2019 16:25:46', 1), 102 | (38, 'thsales061', 5, 'Eaii, beleza?', '22-05-2019 16:26:00', 1), 103 | (39, 'thsales061', 6, 'dsadasd', '22-05-2019 16:44:46', 1), 104 | (40, 'thsales061', 6, 'e1e1e1', '22-05-2019 16:44:51', 1), 105 | (41, 'thsales061', 5, '???', '23-05-2019 12:14:24', 1), 106 | (42, 'rafael065', 5, 'eai, beleza?', '23-05-2019 12:15:13', 1), 107 | (43, 'thsales061', 5, 'Sim, e você?', '23-05-2019 12:15:20', 1), 108 | (44, 'thsales061', 5, 'Beleza...', '23-05-2019 12:15:31', 1), 109 | (45, 'rafael065', 5, 'de boa', '23-05-2019 12:15:44', 1), 110 | (46, 'rafael065', 5, '???', '23-05-2019 12:16:00', 1), 111 | (47, 'thsales061', 0, 'dsad', '23-05-2019 12:38:53', 0), 112 | (48, 'thsales061', 0, 'dsadsad', '23-05-2019 12:39:21', 0), 113 | (49, 'thsales061', 6, 'gfdgfdg', '23-05-2019 13:02:18', 1), 114 | (50, 'thsales061', 5, 'fasfasf', '23-05-2019 13:02:25', 1), 115 | (51, 'thsales061', 6, 'dasdasd', '23-05-2019 13:27:45', 1), 116 | (52, 'thsales061', 6, '1', '23-05-2019 13:34:36', 1), 117 | (53, 'thsales061', 6, 'dasdasd', '23-05-2019 13:35:01', 1), 118 | (54, 'thsales061', 6, 'teste', '23-05-2019 13:36:47', 1), 119 | (55, 'rafael065', 5, 'eai', '23-05-2019 13:37:22', 1), 120 | (56, 'thsales061', 5, 'eai, tudo bem?', '23-05-2019 13:37:30', 1), 121 | (57, 'rafael065', 5, 'Tudo sim, e você?', '23-05-2019 13:39:23', 1), 122 | (58, 'thsales061', 5, 'Tô bem...', '23-05-2019 13:39:28', 1), 123 | (59, 'rafael065', 5, 'Que bom..', '23-05-2019 13:39:32', 1), 124 | (60, 'thsales061', 5, 'Sim :)', '23-05-2019 13:39:35', 1), 125 | (61, 'rafael065', 8, 'Oi', '25-05-2019 13:03:16', 1), 126 | (62, 'isa232', 8, 'Oiiiiiiii', '25-05-2019 13:03:59', 1), 127 | (63, 'isa232', 6, 'ae', '25-05-2019 13:10:55', 1); 128 | 129 | -- -------------------------------------------------------- 130 | 131 | -- 132 | -- Estrutura da tabela `usuarios` 133 | -- 134 | 135 | CREATE TABLE `usuarios` ( 136 | `id` int(20) NOT NULL, 137 | `nome` varchar(200) NOT NULL, 138 | `usuario` varchar(200) NOT NULL, 139 | `email` varchar(200) NOT NULL, 140 | `sexo` int(11) NOT NULL DEFAULT '0', 141 | `senha` varchar(200) NOT NULL, 142 | `foto` varchar(200) NOT NULL, 143 | `status` varchar(200) NOT NULL 144 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 145 | 146 | -- 147 | -- Extraindo dados da tabela `usuarios` 148 | -- 149 | 150 | INSERT INTO `usuarios` (`id`, `nome`, `usuario`, `email`, `sexo`, `senha`, `foto`, `status`) VALUES 151 | (1, 'Thiago Sales', 'thsales061', 'thiago_salests@hotmail.com', 1, '123456', 'images/uploadsnophoto-ce9ebfea85cbfbb4fd42fc2915d12fca8518a1535318fb75d71426ccd3d81e4a.png', '27-05-2019 13:10:04'), 152 | (2, 'Rafael Santos', 'rafael065', 'rafael065@gmail.com', 1, '123', 'https://i0.wp.com/www.winhelponline.com/blog/wp-content/uploads/2017/12/user.png?fit=256%2C256&quality=100&ssl=1', '27-05-2019 12:28:51'), 153 | (3, 'isa Rodrigues', 'isa232', 'isa232@gmail.com', 0, '123', 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Crystal_Clear_kdm_user_female.svg/1024px-Crystal_Clear_kdm_user_female.svg.png', '25-05-2019 13:23:49'), 154 | (4, 'lucas alves', '', 'contato@vivamais.com.br', 0, 'wsbws8g5', '', ''); 155 | 156 | -- 157 | -- Indexes for dumped tables 158 | -- 159 | 160 | -- 161 | -- Indexes for table `chats` 162 | -- 163 | ALTER TABLE `chats` 164 | ADD PRIMARY KEY (`id`); 165 | 166 | -- 167 | -- Indexes for table `mensagens` 168 | -- 169 | ALTER TABLE `mensagens` 170 | ADD PRIMARY KEY (`id`); 171 | 172 | -- 173 | -- Indexes for table `usuarios` 174 | -- 175 | ALTER TABLE `usuarios` 176 | ADD PRIMARY KEY (`id`); 177 | 178 | -- 179 | -- AUTO_INCREMENT for dumped tables 180 | -- 181 | 182 | -- 183 | -- AUTO_INCREMENT for table `chats` 184 | -- 185 | ALTER TABLE `chats` 186 | MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; 187 | 188 | -- 189 | -- AUTO_INCREMENT for table `mensagens` 190 | -- 191 | ALTER TABLE `mensagens` 192 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=64; 193 | 194 | -- 195 | -- AUTO_INCREMENT for table `usuarios` 196 | -- 197 | ALTER TABLE `usuarios` 198 | MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; 199 | COMMIT; 200 | 201 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 202 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 203 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 204 | -------------------------------------------------------------------------------- /lib/class.php: -------------------------------------------------------------------------------- 1 | pdo = $pdo; 9 | 10 | $this->usuario = (isset($_SESSION['usuario']) ? $_SESSION['usuario'] : NULL); 11 | 12 | if($this->usuario != null){ 13 | $this->atualiza_status(); 14 | } 15 | 16 | } 17 | 18 | public function get_explode(){ 19 | $url = (isset($_GET['pagina'])) ? $_GET['pagina'] : 'login'; 20 | return $explode = explode('/', $url); 21 | } 22 | 23 | public function paginacao($pdo){ 24 | $explode = $this->get_explode(); 25 | $dir = "pags/"; 26 | $ext = ".php"; 27 | $validas = array("login", "cadastro"); 28 | 29 | if(file_exists($dir.$explode['0'].$ext) && isset($_SESSION['usuario'])){ 30 | include_once($dir.$explode['0'].$ext); 31 | }else if(file_exists($dir.$explode['0'].$ext) && !isset($_SESSION['usuario'])){ 32 | if(!in_array($explode['0'], $validas)) { 33 | include_once($dir."login".$ext); 34 | }else{ 35 | include_once($dir.$explode['0'].$ext); 36 | } 37 | 38 | }else if(!file_exists($dir.$explode['0'].$ext) && isset($_SESSION['usuario'])){ 39 | echo "Página não encontrada"; 40 | } 41 | } 42 | 43 | public function update_class(){ 44 | $class = array("class='col-sm-8 offset-md-4' style='border:none; background: none;'", "class='col-sm-8'"); 45 | 46 | if(isset($_SESSION['usuario'])){ 47 | return $class[1]; 48 | }else{ 49 | return $class[0]; 50 | } 51 | } 52 | 53 | public function redirect($url){ 54 | echo ""; 55 | } 56 | 57 | public function redirect_direct($url){ 58 | echo ""; 59 | } 60 | 61 | public function alerta($tipo, $mensagem, $col){ 62 | echo "
{$mensagem}
"; 63 | } 64 | 65 | protected function login(){ 66 | if(isset($_POST['env']) && $_POST['env'] == "login"){ 67 | try{ 68 | $stmt = $this->pdo->prepare("SELECT * FROM 69 | usuarios WHERE email = :email AND senha = :senha"); 70 | $stmt->execute(array(':email' => $_POST['email'], ':senha' => $_POST['senha'])); 71 | $total = $stmt->rowCount(); 72 | 73 | if($total > 0){ 74 | $dados = $stmt->fetch(PDO::FETCH_ASSOC); 75 | $_SESSION['usuario'] = $dados['usuario']; 76 | $this->alerta('success', 'Logado com sucesso...', 'col-sm-6'); 77 | $this->redirect('inicio'); 78 | }else{ 79 | $this->alerta('danger', 'Usuário ou senha inválidos', 'col-sm-6'); 80 | } 81 | 82 | 83 | 84 | }catch(PDOException $e){ 85 | return $e->getMessage(); 86 | } 87 | 88 | 89 | } 90 | } 91 | 92 | public function cadastro(){ 93 | if(isset($_POST['env']) && $_POST['env'] == "cad"){ 94 | $status = $this->verifica_cadastro($_POST['email'], $_POST['usuario']); 95 | $post_dados = array($_POST['nome'], $_POST['usuario'], $_POST['email'], $_POST['senha'], $_POST['sexo']); 96 | $uploaddir = 'images/uploads/'; 97 | $uploadfile = $uploaddir.basename($_FILES['userfile']['name']); 98 | 99 | if($status == TRUE){ 100 | try{ 101 | $stmt = $this->pdo->prepare("INSERT INTO usuarios (nome, usuario, email, senha, sexo, foto) VALUES(:nome, :usuario, :email, :senha, :sexo, :foto)"); 102 | $stmt->execute(array(':nome' => $post_dados[0], 103 | ':usuario' => $post_dados[1], 104 | ':email' => $post_dados[2], 105 | ':senha' => $post_dados[3], 106 | ':sexo' => $post_dados[4], 107 | ':foto' => $uploadfile)); 108 | $conta = $stmt->rowCount(); 109 | 110 | if($conta > 0){ 111 | move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); 112 | $this->alerta("success", "Cadastro efetuado com sucesso! Aguarde...", false); 113 | $this->redirect("login"); 114 | 115 | } 116 | 117 | }catch(PDOException $e){ 118 | $e->getMessage(); 119 | } 120 | }else{ 121 | echo "
Usuário ou email já cadastrados, tente outro!
"; 122 | } 123 | } 124 | } 125 | 126 | public function verifica_cadastro($email, $usuario){ 127 | try{ 128 | $stmt = $this->pdo->prepare("SELECT * FROM usuarios WHERE usuario = :usuario OR email = :email"); 129 | $stmt->execute(array(':usuario' => $usuario, ':email' => $email)); 130 | $total = $stmt->rowCount(); 131 | 132 | if($total > 0){ 133 | return false; 134 | }else{ 135 | return true; 136 | } 137 | }catch(PDOException $e){ 138 | $e->getMessage(); 139 | } 140 | } 141 | 142 | public function atualiza_status(){ 143 | $dataAtualizada = date('d-m-Y H:i:s', strtotime('+2 minutes')); 144 | 145 | try{ 146 | $stmt = $this->pdo->prepare("UPDATE usuarios SET status = :status WHERE usuario = :usuario"); 147 | $stmt->execute(array(':status' => $dataAtualizada, ':usuario' => $this->usuario)); 148 | }catch(PDOException $e){ 149 | echo $e->getMessage(); 150 | } 151 | } 152 | 153 | public function get_status($usuario){ 154 | $dataUser = $this->dados_user($usuario, "status"); 155 | $data = $this->get_data(); 156 | 157 | if($data <= $dataUser){ 158 | return ""; 159 | } 160 | } 161 | 162 | public function verifica_chat($id_para){ 163 | try{ 164 | $stmt = $this->pdo->prepare("SELECT * FROM chats WHERE id_de = :id_de AND id_para = :id_para OR id_de = :id_para AND id_para = :id_de"); 165 | $stmt->execute(array(':id_de' => $this->usuario, ':id_para' => $id_para)); 166 | $total = $stmt->rowCount(); 167 | 168 | if($total > 0){ 169 | $dados = $stmt->fetch(PDO::FETCH_ASSOC); 170 | $this->redirect_direct("chat/{$dados['id']}"); 171 | exit(); 172 | }else{ 173 | $this->cria_chat($id_para); 174 | exit(); 175 | } 176 | }catch(PDOException $e){ 177 | echo $e->getMessage(); 178 | } 179 | } 180 | 181 | public function cria_chat($id_para){ //falta adicionar a data 182 | $data = $this->get_data(); 183 | try{ 184 | $stmt = $this->pdo->prepare("INSERT INTO chats (id_de, id_para) VALUES (:id_de, :id_para)"); 185 | $stmt->execute(array(':id_de' => $this->usuario, ':id_para' => $id_para)); 186 | $id = $this->pdo->lastInsertId(); 187 | 188 | $this->redirect_direct("chat/{$id}"); 189 | exit(); 190 | }catch(PDOException $e){ 191 | echo $e->getMessage(); 192 | } 193 | } 194 | 195 | 196 | public function get_data(){ 197 | date_default_timezone_set('America/Sao_Paulo'); 198 | return date('d-m-Y H:i:s'); 199 | } 200 | 201 | public function diferencia_datas($data1){ 202 | 203 | $data1 = new DateTime($data1); 204 | $data2 = new DateTime($this->get_data()); 205 | 206 | $intervalo = $data1->diff($data2); 207 | 208 | if($intervalo->y > 1){ 209 | return $intervalo->y." Anos atrás"; 210 | }elseif($intervalo->y == 1){ 211 | return $intervalo->y." Ano atrás"; 212 | }elseif($intervalo->m > 1){ 213 | return $intervalo->m." Meses atrás"; 214 | }elseif($intervalo->m == 1){ 215 | return $intervalo->m." Mês atrás"; 216 | }elseif($intervalo->d > 1){ 217 | return $intervalo->d." Dias atrás"; 218 | }elseif($intervalo->d > 0){ 219 | return $intervalo->d." Dia atrás"; 220 | }elseif($intervalo->h > 0){ 221 | return $intervalo->h." Horas atrás"; 222 | }elseif($intervalo->i > 1 && $intervalo->i < 59){ 223 | return $intervalo->i." Minutos atrás"; 224 | }elseif($intervalo->i == 1){ 225 | return $intervalo->i." Minuto atrás"; 226 | }elseif($intervalo->s < 60 && $intervalo->i <= 0){ 227 | return $intervalo->s." Segundo atrás"; 228 | } 229 | } 230 | 231 | 232 | public function dados_user($usuario, $arr){ 233 | try{ 234 | $stmt = $this->pdo->prepare("SELECT * FROM usuarios WHERE usuario = :usuario"); 235 | $stmt->execute(array(':usuario' => $usuario)); 236 | $conta = $stmt->rowCount(); 237 | 238 | if($conta > 0){ 239 | $dados = $stmt->fetch(PDO::FETCH_ASSOC); 240 | return $dados[$arr]; 241 | } 242 | }catch(PDOException $e){ 243 | $e->getMessage(); 244 | } 245 | } 246 | 247 | 248 | public function pega_chats($id_de){ 249 | try{ 250 | $stmt = $this->pdo->prepare("SELECT * FROM chats WHERE id_de = :id_de OR id_para = :id_de ORDER BY lastupdate DESC"); 251 | $stmt->execute(array(':id_de' => $id_de)); 252 | $count = $stmt->rowCount(); 253 | 254 | while($dados = $stmt->fetch(PDO::FETCH_ASSOC)){ 255 | $this->pega_mensagem_chat($dados['id']); 256 | } 257 | }catch(PDOException $e){ 258 | echo $e->getMessage(); 259 | } 260 | } 261 | 262 | public function pega_mensagem_chat($id){ 263 | try{ 264 | $sql = $this->pdo->prepare("SELECT * FROM mensagens WHERE id_chat = :id_chat ORDER BY id DESC LIMIT 1"); 265 | $sql->execute(array(':id_chat' => $id)); 266 | 267 | while($dsql = $sql->fetch(PDO::FETCH_ASSOC)){ 268 | 269 | echo "{$this->verifica_chat_ativo($id)} 270 |
271 |
272 |
273 |
{$this->get_status($this->dados_user($this->verifica_nomes_chat($id),"usuario"))} 274 | {$this->dados_user($this->verifica_nomes_chat($id),"nome")} {$this->diferencia_datas($dsql['data'])}
275 |

{$dsql['mensagem']}

276 |
277 |
278 | "; 279 | 280 | } 281 | }catch(PDOException $e){ 282 | echo $e->getMessage(); 283 | } 284 | } 285 | 286 | public function verifica_nomes_chat($id){ 287 | try{ 288 | $stmt = $this->pdo->prepare("SELECT * FROM chats WHERE id = :id"); 289 | $stmt->execute(array(':id' => $id)); 290 | 291 | $dados = $stmt->fetch(PDO::FETCH_ASSOC); 292 | 293 | if($dados['id_de'] == $this->usuario ){ 294 | return $dados['id_para']; 295 | }else if ($dados['id_para'] == $this->usuario){ 296 | return $dados['id_de']; 297 | } 298 | }catch(PDOException $e){ 299 | return $e->getmessage(); 300 | } 301 | 302 | } 303 | 304 | public function verifica_chat_ativo($id){ 305 | //$explode = $this->get_explode(); 306 | if(isset($_GET['atual']) && $_GET['atual'] == $id){ 307 | echo "
"; 308 | }else{ 309 | echo "
"; 310 | } 311 | } 312 | 313 | public function insere_mensagem(){ 314 | //$explode = $this->get_explode(); 315 | $get = (isset($_GET['atual']) ? $_GET['atual'] : NULL); 316 | 317 | $form = array($this->usuario, $get, date("d-m-Y H:i:s")); 318 | if(isset($_POST['env']) && $_POST['env'] == "ms"){ 319 | 320 | try{ 321 | $stmt = $this->pdo->prepare("INSERT INTO mensagens (id_de, id_chat, mensagem, data) VALUES(:id_de, :id_chat, :mensagem, :data)"); 322 | $stmt->execute(array(':id_de' => $form['0'], 323 | ':id_chat' => $form['1'], 324 | ':mensagem' => $_POST['msg'], 325 | ':data' => $form['2'])); 326 | $this->atualiza_tempo_chat($get); 327 | return json_encode(array("success" => TRUE)); 328 | }catch(PDOException $e){ 329 | return json_encode(array("success" => FALSE, "error" => $e->getMessage())); 330 | } 331 | } 332 | } 333 | 334 | public function form_mensagem(){ 335 | $this->insere_mensagem(); 336 | } 337 | 338 | protected function atualiza_tempo_chat($id){ 339 | $data = $this->get_data(); 340 | 341 | try{ 342 | $stmt = $this->pdo->prepare("UPDATE chats SET lastupdate = :data WHERE id = :id"); 343 | $stmt->execute(array(':data' => $data, ':id' => $id)); 344 | }catch(PDOException $e){ 345 | echo $e->getMessage(); 346 | } 347 | 348 | } 349 | 350 | public function atualiza_lido($id){ 351 | try{ 352 | $stmt = $this->pdo->prepare("UPDATE mensagens SET lido = 1 WHERE id_de != :id_de AND id_chat = :id_chat"); 353 | $stmt->execute(array(':id_de' => $this->usuario, ':id_chat' => $id)); 354 | }catch(PDOException $e){ 355 | echo $e->getMessage(); 356 | } 357 | 358 | } 359 | 360 | public function verifica_logado(){ 361 | if($this->usuario != NULL){ 362 | echo ""; 363 | exit(); 364 | } 365 | } 366 | 367 | public function get_onlines($sexo){ 368 | $data = $this->get_data(); 369 | try{ 370 | if($sexo == 2){ 371 | $stmt = $this->pdo->prepare("SELECT * FROM usuarios WHERE status >= :data AND usuario <> :usuario LIMIT 50"); 372 | $stmt->execute(array(':data' => $data, ':usuario' => $this->usuario)); 373 | }else{ 374 | $stmt = $this->pdo->prepare("SELECT * FROM usuarios WHERE sexo = :sexo AND status >= :data AND usuario <> :usuario LIMIT 50"); 375 | $stmt->execute(array(':sexo' => $sexo, ':data' => $data, ':usuario' => $this->usuario)); 376 | } 377 | 378 | $conta = $stmt->rowCount(); 379 | 380 | if($conta > 0){ 381 | while($dados = $stmt->fetch(PDO::FETCH_ASSOC)){ 382 | $separa_nome = explode(' ', $dados['nome']); 383 | echo "
384 |
385 | ".ucfirst($separa_nome['0'])." 386 |
387 |
"; 388 | } 389 | } 390 | }catch(PDOException $e){ 391 | echo $e->getMessage(); 392 | } 393 | } 394 | 395 | 396 | public function editar_dados(){ 397 | if(isset($_POST['env']) && $_POST['env'] == "alt"){ 398 | //move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile) 399 | $uploaddir = 'images/uploads'; 400 | $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); 401 | if($_FILES['userfile']['size'] <= 0 ){ 402 | $stmt = $this->pdo->prepare("UPDATE usuarios SET nome = :nome, email = :email, senha = :senha, sexo = :sexo WHERE usuario = :usuario"); 403 | $stmt->execute(array(':nome' => $_POST['nome'], 404 | ':email' => $_POST['email'], 405 | ':senha' => $_POST['senha'], 406 | ':sexo' => $_POST['sexo'], 407 | ':usuario' => $this->usuario)); 408 | }else{ 409 | $stmt = $this->pdo->prepare("UPDATE usuarios SET nome = :nome, email = :email, senha = :senha, sexo = :sexo, foto = :foto WHERE usuario = :usuario"); 410 | $stmt->execute(array(':nome' => $_POST['nome'], 411 | ':email' => $_POST['email'], 412 | ':senha' => $_POST['senha'], 413 | ':sexo' => $_POST['sexo'], 414 | ':foto' => $uploadfile, 415 | ':usuario' => $this->usuario)); 416 | move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); 417 | } 418 | 419 | if($stmt->rowCount() > 0){ 420 | $this->alerta("success", "Dados alterados com sucesso!", false); 421 | $this->redirect("configs"); 422 | }else{ 423 | echo "Erro: ".$this->pdo->errorInfo(); 424 | } 425 | 426 | 427 | } 428 | } 429 | 430 | } 431 | ?> -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------