datastores.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  5. function connect(){
  6. $link = mysql_connect('127.0.0.1','eligibilite','B3Kg7z6d') or die(mysql_error());
  7. mysql_select_db('eligibilite', $link) or die(mysql_error());
  8. }
  9. function executeQuery($requete) {
  10. $resultat = mysql_query($requete) or die(mysql_error());
  11. if(substr($requete, 0, 6) === 'SELECT'){
  12. while($donnees = mysql_fetch_array($resultat)){
  13. $resultats[] = $donnees;
  14. }
  15. if (!isset($resultats)) {
  16. return null;
  17. }
  18. return $resultats;
  19. }
  20. else if(substr($requete, 0, 6) === 'INSERT'){
  21. $resultats = mysql_insert_id();
  22. }
  23. else {
  24. $resultats = 'ok';
  25. }
  26. return $resultats;
  27. }
  28. connect();
  29. if(isset($_POST['query'])) {
  30. $resultat = executeQuery($_POST['query']);
  31. echo json_encode($resultat);
  32. return;
  33. }
  34. if(isset($_POST['mail'])) {
  35. $email = 'ftth@manchenumerique.fr';
  36. $bcc = 'ftth@manchenumerique.fr';
  37. if(isset($_POST['siteEmail'])) {
  38. $email = $_POST['siteEmail'];
  39. }
  40. $headers = "";
  41. $headers .= "Reply-To:".$email."\r\n"."X-Mailer: PHP/".phpversion(). "\r\n";
  42. $headers .= "MIME-Version: 1.0"."\r\n";
  43. $headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
  44. $headers .= "Bcc: ".$bcc."\r\n";
  45. $headers .= "From: ".utf8_decode("Manche Numérique")." <".$email.">"."\r\n";
  46. $subject = utf8_decode($_POST['mail']['sujet']);
  47. $subject = mb_encode_mimeheader($subject, "UTF-8");
  48. // Envoi
  49. $to = $_POST['mail']['to'];
  50. $resultat = mail($to, $subject, utf8_decode($_POST['mail']['message']), $headers, "-f ".$email);
  51. }
  52. if(isset($resultat)){
  53. echo json_encode($resultat);
  54. }
  55. ?>