get.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. if (!isset($_POST['details'])) {
  3. http_response_code(400);
  4. exit;
  5. }
  6. try {
  7. // Fazendo login no wekan:
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL,"http://200.144.254.107/wekan/users/login");
  10. curl_setopt($ch, CURLOPT_POST, 1);
  11. curl_setopt($ch, CURLOPT_POSTFIELDS,
  12. "username=ivprogsite&password=T2mWR4vNr7tVwpTVR2gS");
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. $server_output = curl_exec($ch);
  15. curl_close ($ch);
  16. $dadosLogin = json_decode($server_output);
  17. if (!$dadosLogin) {
  18. throw new Exception();
  19. }
  20. // Preparando o texto para submeter ao wekan:
  21. $details = '';
  22. if (isset($_POST['name']) && !empty(trim($_POST['name']))) {
  23. $details .= 'Nome: ' . strip_tags(trim($_POST['name'])) . '\n';
  24. }
  25. if (isset($_POST['email']) && !empty(trim($_POST['email']))) {
  26. $details .= 'E-mail: ' . strip_tags(trim($_POST['email'])) . '\n';
  27. }
  28. $details .= 'Detalhes: ' . strip_tags(trim($_POST['details']));
  29. $summary = '';
  30. if (isset($_POST['summary']) && !empty(trim($_POST['summary']))) {
  31. $summary = strip_tags(trim($_POST['summary']));
  32. }
  33. // Fazendo a submissão dos dados para o Wekan:
  34. $ch = curl_init();
  35. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  36. 'Authorization: Bearer ' . $dadosLogin->token,
  37. 'Content-type:application/json'
  38. ));
  39. curl_setopt($ch, CURLOPT_URL,"http://200.144.254.107/wekan/api/boards/v82Wx3C3dk79t4pJw/lists/dHNhYSSyyqWhRn6NX/cards");
  40. curl_setopt($ch, CURLOPT_POST, 1);
  41. curl_setopt($ch, CURLOPT_POSTFIELDS,
  42. '{ "title": "'.$summary.'", "description": "'.$details.'", "authorId": "'. $dadosLogin->id.'", "swimlaneId": "HeJBje3EdmJ3GpZyb" }');
  43. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  44. $retorno = curl_exec($ch);
  45. curl_close ($ch);
  46. $resposta = json_decode($retorno);
  47. if (!$resposta->_id) {
  48. throw new Exception();
  49. }
  50. } catch (Exception $ex) {
  51. if (isset($_POST['redirect'])) {
  52. header('Location:'.$_POST['redirect'].'?error=true');
  53. exit;
  54. } else {
  55. // send error status instead
  56. // header('Location:report.html?error=true');
  57. http_response_code(500);
  58. exit;
  59. }
  60. }
  61. if (isset($_POST['redirect'])) {
  62. header('Location:'.$_POST['redirect'].'?reported=true');
  63. exit;
  64. } else {
  65. // send ok status instead
  66. // header('Location:report.html?reported=true');
  67. http_response_code(200);
  68. exit;
  69. }
  70. ?>