Guest User

Untitled

a guest
Jun 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. <div id="a" class="contatos"><center>Contatos</center>
  2.  
  3. <?php
  4. foreach ($contatos as $contato):
  5. if ($contato['estadoContato'] != 'Desativado') {
  6. echo '<div id = "contato' . $cont . '" class = "contato" onclick="abrirMensagem(event); ">';
  7. if ($contato['nome'] === null) {
  8. echo 'vazio';
  9. } else {
  10. echo '<center>' . $contato['nome'] . '</center>';
  11. echo '<img src="fotos/' . $contato['foto'] . '" width="40px" height="40px">';
  12. $_SESSION['contato' . $cont] = $contato[$cpfxml];
  13. }
  14. echo '</div>';
  15. }
  16. $cont++;
  17. endforeach;
  18. ?>
  19.  
  20. </div>
  21. <div id="b" class="mensagem"><center>Mensagens</center>
  22. <?PHP
  23. // tentativa com o Post
  24. if (isset($_POST['nomeXML'])){
  25. $nomearquivo = $_POST['nomeXML'];
  26. $dom = $_SESSION['dom'];
  27. $dom->load($nomearquivo);
  28. $_SESSION['dom'] = null;
  29. $ver = simplexml_import_dom($dom);
  30. foreach ($ver as $xml):
  31. echo "<center><p>" . $xml->mensagem . "</p></center>";
  32. endforeach;
  33. }
  34. ?>
  35.  
  36. </div>
  37. <div class="enviarMensagem">
  38. <form>
  39. <input type="text" name="txtmsg" placeholder="Digite sua mensagem"><input type="submit" value="Enviar" name="btn">
  40. </form>
  41. </div>
  42. <style type="text/css">
  43. .contatos
  44. {
  45. width: 300px;
  46. height: 600px;
  47. background-color: blue;
  48. float: left;
  49. overflow:auto;
  50. }
  51. .contato
  52. {
  53. width: 290px;
  54. height: 100px;
  55. margin-left:5px;
  56. background-color: yellow;
  57. float: left;
  58. }
  59. .mensagem
  60. {
  61. margin-left:400px;
  62. width: 600px;
  63. height: 600px;
  64. background-color: red;
  65. overflow:auto;
  66. }
  67. .enviarMensagem
  68. {
  69. margin-left:400px;
  70. }
  71.  
  72. </style>
  73. <script>
  74. function abrirMensagem(event) {
  75. $.post("adminMensagens.php", {
  76. cpfContato: event.target.id, cpflogado: <?php echo $cpf; ?>
  77. }, function (msg) {
  78. $("#teste").html(msg);
  79. })
  80. }
  81.  
  82. </script>
  83. </body>
  84. </html>
  85.  
  86. header('Content-Type: text/html; charset=utf-8');
  87. require_once 'conexao.php';
  88. require_once 'banco-mensagens.php';
  89. session_start();
  90.  
  91. // para carregar a mensagem
  92. if ((isset($_POST['cpfContato'])) && (isset($_POST['cpflogado']))) {
  93. $cpfContato = $_POST['cpfContato'];
  94. $cpfContato = $_SESSION[$cpfContato];
  95. $cpflogado = $_POST['cpflogado'];
  96. // <?xml version="1.0" encoding="UTF-8"
  97. $dom = new DOMDocument("1.0", "ISO-8859-7");
  98. lerXML($dom, $conexao, $cpfContato, $cpflogado, $_SESSION['tipoUsuarioLogado']);
  99. $_SESSION['dom'] = $dom;
  100. mandarNomeXML($_SESSION['nomeXML']);
  101. }
  102.  
  103. function mandarNomeXML($nomeXML) {
  104. $content = http_build_query(array(
  105. 'nomeXML' => $nomeXML,
  106. ));
  107. $context = stream_context_create(array(
  108. 'http' => array(
  109. 'method' => 'POST',
  110. 'content' => $content,
  111. )
  112. ));
  113. $result = file_get_contents('pag_mensagens.php', null, $context);
  114. return $result;
  115. }
  116.  
  117. header('Content-Type: text/html; charset=utf-8');
  118.  
  119. function listarContatos($conexao, $cpf, $tipo) {
  120. $contatos = array();
  121. if ($tipo == 2) {
  122. $sql = "select * from carregarContatoTec where cpf_cliente_fk = $cpf";
  123. } else {
  124. $sql = "select * from carregarContatoCli where cpf_tecnico_fk = $cpf";
  125. }
  126. $resultado = mysqli_query($conexao, $sql);
  127. while ($contato = mysqli_fetch_assoc($resultado)) {
  128. array_push($contatos, $contato);
  129. }
  130. return $contatos;
  131. }
  132.  
  133. function addMensagem($documento, $mensagem, $cpf_origem) {
  134. // criar msg
  135. $msg = $documento->createElement("msg");
  136. // criar nó data
  137. $data = date('j/n/Y H:i:s');
  138. $dataElm = $documento->createElement("data_envio", $data);
  139. // criar nó origem
  140. $cpf_origemElm = $documento->createElement("cpf_origem", $cpf_origem);
  141. // criar nó mensagem (texto)
  142. $mensagemElm = $documento->createElement("mensagem", $mensagem);
  143.  
  144. $msg->appendChild($dataElm);
  145. $msg->appendChild($cpf_origemElm);
  146. $msg->appendChild($mensagemElm);
  147. return $msg;
  148. }
  149.  
  150. function gerarNomeXML() {
  151. $dir = "xml_msg";
  152. $novonome = $dir . "/" . md5(uniqid(time())) . ".xml";
  153. return $novonome;
  154. }
  155.  
  156. function lerXML($dom, $conexao, $cpfCli, $cpfTec, $tipo) {
  157. if ($tipo === 2) {
  158. $sql = "select caminho_xml as xml from tbl_mensagem where cpf_cliente_fk = $cpfCli and cpf_tecnico_fk = $cpfTec";
  159. } else {
  160. $sql = "select caminho_xml as xml from tbl_mensagem where cpf_cliente_fk = $cpfTec and cpf_tecnico_fk = $cpfCli";
  161. }
  162. $return = mysqli_query($conexao, $sql);
  163. $row = mysqli_fetch_array($return, MYSQLI_ASSOC);
  164. $nomeArquivo = $row["xml"];
  165. if (!file_exists($nomeArquivo)) {
  166. $novonome = gerarNomeXML();
  167. guardarXML($conexao, $novonome, $cpfCli, $cpfTec, $tipo);
  168. $msg = addMensagem($dom, "Conectados!", null);
  169. // criando nó principal
  170. $root = $dom->createElement("mensagens");
  171. // adiciona a mensagem ao root
  172. $root->appendChild($msg);
  173. // adiciona o root ao xml
  174. $dom->appendChild($root);
  175. // retirar os espaços em branco
  176. $dom->preserveWhiteSpace = false;
  177. // gerar código ??
  178. $dom->formatOutput = true;
  179. $_SESSION['nomeXML'] = $novonome;
  180. $dom->save($novonome);
  181. return $root;
  182. } else {
  183. // carrega o arquivo
  184. $dom->load($nomeArquivo);
  185. $_SESSION['nomeXML'] = $nomeArquivo;
  186. // recupera nó principal
  187. $root = $dom->documentElement;
  188. return $root;
  189. }
  190. }
  191.  
  192. function guardarXML($conexao, $caminho, $cpfCli, $cpfTec, $tipo) {
  193. if ($tipo == 2) {
  194. $sql = "update tbl_mensagem set caminho_xml = '$caminho' where cpf_cliente_fk = $cpfTec and cpf_tecnico_fk = $cpfCli";
  195. } else {
  196. $sql = "update tbl_mensagem set caminho_xml = '$caminho' where cpf_cliente_fk = $cpfCli and cpf_tecnico_fk = $cpfTec";
  197. }
  198. $resultado = mysqli_query($conexao, $sql);
  199. return $resultado;
  200. }
Add Comment
Please, Sign In to add comment